You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Indent using 2 spaces rather than tabs to conserve space and help prevent line wrapping. Be sure to set this preference in Xcode.
48
-
* Method braces and other braces (`if`/`else`/`switch`/`while` etc.) always open on the same line as the statement but close on a new line.
49
-
50
-
**Preferred:**
51
-
```swift
52
-
if user.isHappy {
53
-
//Do something
54
-
} else {
55
-
//Do something else
56
-
}
57
-
```
58
-
59
-
**Not Preferred:**
60
-
```swift
61
-
if user.isHappy
62
-
{
63
-
//Do something
64
-
}
65
-
else {
66
-
//Do something else
67
-
}
68
-
```
69
-
70
-
* There should be exactly one blank line between methods to aid in visual clarity and organization. Whitespace within methods should separate functionality, but having too many sections in a method often means you should refactor into several methods.
71
-
72
-
## Comments
73
-
74
-
When they are needed, use comments to explain **why** a particular piece of code does something. Comments must be kept up-to-date or deleted.
75
-
76
-
Avoid block comments inline with code, as the code should be as self-documenting as possible. *Exception: This does not apply to those comments used to generate documentation.*
77
-
78
-
79
31
## Naming
80
32
81
33
Use descriptive names with camel case for classes, methods, variables, etc. Class names and constants in module scope should be capitalized, while method names and variables should start with a lower case letter.
@@ -125,11 +77,14 @@ class Guideline {
125
77
126
78
When referring to functions in prose (tutorials, books, comments) include the required parameter names from the caller's perspective.
127
79
128
-
129
80
> The `dateFromString()` function is great.
81
+
>
130
82
> Call `convertPointAt(column:, row:)` from your `init()` method.
83
+
>
131
84
> The return value of `timedAction(delay:, perform:)` may be nil.
85
+
>
132
86
> Guideline objects only have two methods: `combineWithString(options:)` and `upvoteBy()`
87
+
>
133
88
> You shouldn't call the data source method `tableView(cellForRowAtIndexPath:)` directly.
134
89
135
90
@@ -154,25 +109,39 @@ If you need to expose a Swift type for use within Objective-C you can provide a
154
109
```
155
110
156
111
157
-
## Semicolons
158
-
159
-
Swift does not require a semicolon after each statement in your code. They are only required if you wish to combine multiple statements on a single line.
160
-
161
-
Do not write multiple statements on a single line separated with semicolons.
112
+
## Spacing
162
113
163
-
The only exception to this rule is the `for-conditional-increment` construct, which requires semicolons. However, alternative `for-in` constructs should be used where possible.
114
+
* Indent using 2 spaces rather than tabs to conserve space and help prevent line wrapping. Be sure to set this preference in Xcode.
115
+
* Method braces and other braces (`if`/`else`/`switch`/`while` etc.) always open on the same line as the statement but close on a new line.
164
116
165
117
**Preferred:**
166
118
```swift
167
-
var swift ="not a scripting language"
119
+
if user.isHappy {
120
+
//Do something
121
+
} else {
122
+
//Do something else
123
+
}
168
124
```
169
125
170
126
**Not Preferred:**
171
127
```swift
172
-
var swift ="not a scripting language";
128
+
if user.isHappy
129
+
{
130
+
//Do something
131
+
}
132
+
else {
133
+
//Do something else
134
+
}
173
135
```
174
136
175
-
**NOTE**: Swift is very different to JavaScript, where omitting semicolons is [generally considered unsafe](http://stackoverflow.com/questions/444080/do-you-recommend-using-semicolons-after-every-statement-in-javascript)
137
+
* There should be exactly one blank line between methods to aid in visual clarity and organization. Whitespace within methods should separate functionality, but having too many sections in a method often means you should refactor into several methods.
138
+
139
+
## Comments
140
+
141
+
When they are needed, use comments to explain **why** a particular piece of code does something. Comments must be kept up-to-date or deleted.
142
+
143
+
Avoid block comments inline with code, as the code should be as self-documenting as possible. *Exception: This does not apply to those comments used to generate documentation.*
144
+
176
145
177
146
## Classes and Structures
178
147
@@ -217,7 +186,7 @@ The example above demonstrates the following style guidelines:
217
186
+ Indent getter and setter definitions and property observers.
218
187
+ Define multiple variables and structures on a single line if they share a common purpose / context.
219
188
220
-
## Use of Self
189
+
###Use of Self
221
190
222
191
Avoid using `self` since Swift does not require it to access an object's properties or invoke its methods.
223
192
@@ -386,6 +355,40 @@ for var i = 0; i < attendeeList.count; i++ {
386
355
```
387
356
388
357
358
+
## Semicolons
359
+
360
+
Swift does not require a semicolon after each statement in your code. They are only required if you wish to combine multiple statements on a single line.
361
+
362
+
Do not write multiple statements on a single line separated with semicolons.
363
+
364
+
The only exception to this rule is the `for-conditional-increment` construct, which requires semicolons. However, alternative `for-in` constructs should be used where possible.
365
+
366
+
**Preferred:**
367
+
```swift
368
+
var swift ="not a scripting language"
369
+
```
370
+
371
+
**Not Preferred:**
372
+
```swift
373
+
var swift ="not a scripting language";
374
+
```
375
+
376
+
**NOTE**: Swift is very different to JavaScript, where omitting semicolons is [generally considered unsafe](http://stackoverflow.com/questions/444080/do-you-recommend-using-semicolons-after-every-statement-in-javascript)
377
+
378
+
## Language
379
+
380
+
Use US English spelling to match Apple's API.
381
+
382
+
**Preferred:**
383
+
```swift
384
+
var color ="red"
385
+
```
386
+
387
+
**Not Preferred:**
388
+
```swift
389
+
var colour ="red"
390
+
```
391
+
389
392
## Smiley Face
390
393
391
394
Smiley faces are a very prominent style feature of the raywenderlich.com site! It is very important to have the correct smile signifying the immense amount of happiness and excitement for the coding topic. The closing square bracket `]` is used because it represents the largest smile able to be captured using ASCII art. A closing parenthesis `)` creates a half-hearted smile, and thus is not preferred.
0 commit comments