-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathswift.code-snippets
137 lines (137 loc) · 3.87 KB
/
swift.code-snippets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
{
"API Availability": {
"prefix": "@available",
"body": [
"@available(${1:iOS, macOS, tvOS, watchOS} ${2:x.y.z}, *)",
],
"description": "Define an API's minimum version"
},
"Availability Conditional": {
"prefix": "#available",
"body": [
"if #available(${1:iOS, macOS, tvOS, watchOS} ${2:x.y.z}, *) {",
"\t${3:API available statements}",
"} else {",
"\t${4:fallback statements}",
"}"
],
"description": "Conditionally execute code based on whether the API is available at runtime."
},
"Defer": {
"prefix": "defer",
"body": [
"defer {",
"\t${1:deferred statements}",
"}",
],
"description": "Executes a set of statements before execution leaves the current block of code."
},
"Deinitialization Declaration": {
"prefix": "deinit",
"body": [
"deinit {",
"\t${1:deferred statements}",
"}",
],
"description": "Performs cleanup before an object is deallocated."
},
"Deprecated": {
"prefix": "deprecated",
"body": [
"@available(*, deprecated, message: \"${2:String}\")",
],
"description": "Define availability"
},
"Deprecated with Version": {
"prefix": "deprecated",
"body": [
"@available(${1:platform}, introduced: ${2:version}, deprecated: ${3:version}, message: \"${4:String}\")",
],
"description": "Define availability"
},
"Import Statement": {
"prefix": "import",
"body": [
"import ${1:module}"
],
"description": "Allows access to symbols declared in the specified module."
},
"Initializer Declaration": {
"prefix": "init",
"body": [
"init(${1:parameters}) {",
"\t${2:statements}",
"}"
],
"description": "A set of statements that prepares an instance of a class, structure, or enumeration for use."
},
"Lazy Closure Stored Property Declaration": {
"prefix": "lazyvarclosure",
"body": [
"lazy var ${1:property name}: ${2:type name} = {",
"\t${3:statements}",
"\treturn ${4:value}",
"}()"
],
"description": "A property whose initial value is lazily set to the result of a closure."
},
"Lazy Stored Property Declaration": {
"prefix": "lazyvar",
"body": [
"lazy var ${1:property name} = ${2:expression}"
],
"description": "A property whose initial value is not calculated until the first time it is used."
},
"Let Declaration": {
"prefix": "let",
"body": [
"let ${1:name} = ${2:value}"
],
"description": "Creates a variable that cannot be changed."
},
"OptionSet": {
"prefix": "optionset",
"body": [
"struct ${1:name}: OptionSet {",
"\tlet rawValue: ${2:integer type}",
"",
"\tstatic let ${3:optionA} = ${1:name}(rawValue: 1 << 0)",
"\tstatic let ${5:optionB} = ${1:name}(rawValue: 1 << 1)",
"\tstatic let ${7:optionC} = ${1:name}(rawValue: 1 << 2)",
"",
"\tstatic let all: ${1:name} = [.${3:optionA}, .${5:optionB}, .${7:optionC}]",
"}"
],
"description": "A mathematical set interface to a bit set."
},
"Renamed": {
"prefix": "renamed",
"body": [
"@available(*, deprecated, renamed: \"${1:renamed}\", message: \"${2:String}\")",
],
"description": "Indicate API has moved"
},
"Required Initializer Declaration": {
"prefix": "requiredinit",
"body": [
"required init(${1:parameters}) {",
"\t${2:statements}",
"}"
],
"description": "An initializer that must be implemented by every subclass."
},
"Typealias Declaration": {
"prefix": "typealias",
"body": [
"typealias ${1:type name} = ${2:type expression}"
],
"description": "Defines an alternate name for an existing type."
},
"Var Declaration": {
"prefix": "var",
"body": [
"var ${1:name} = ${2:value}"
],
"description": "Creates a variable that can be changed."
}
}