@@ -21,6 +21,7 @@ Writing Objective-C? Check out our [Objective-C Style Guide](https://github.com/
21
21
* [ Constants] ( #constants )
22
22
* [ Optionals] ( #optionals )
23
23
* [ Type Inference] ( #type-inference )
24
+ * [ Syntactic Sugar] ( #syntactic-sugar )
24
25
* [ Control Flow] ( #control-flow )
25
26
* [ Use of Self] ( #use-of-self )
26
27
* [ Smiley Face] ( #smiley-face )
@@ -238,15 +239,15 @@ class BoardLocation {
238
239
Keep short function declarations on one line including the opening brace:
239
240
240
241
``` swift
241
- func reticulateSplines (spline : Double [ ]) -> Bool {
242
+ func reticulateSplines (spline : [ Double ]) -> Bool {
242
243
// reticulate code goes here
243
244
}
244
245
```
245
246
246
247
For functions with long signatures, add line breaks at appropriate points and add an extra indent on subsequent lines:
247
248
248
249
``` swift
249
- func reticulateSplines (spline : Double [ ], adjustmentFactor : Double ,
250
+ func reticulateSplines (spline : [ Double ], adjustmentFactor : Double ,
250
251
translateConstant : Int , comment : String ) -> Bool {
251
252
// reticulate code goes here
252
253
}
@@ -337,14 +338,34 @@ var currentBounds: CGRect = computeViewBounds()
337
338
** NOTE** : Following this guideline means picking descriptive names is even more important than before.
338
339
339
340
341
+ ### Syntactic Sugar
342
+
343
+ Prefer the shortcut versions of type declarations over the full generics syntax.
344
+
345
+ ** Preferred:**
346
+ ``` swift
347
+ var deviceModels: [String ]
348
+ var employees: [Int : String ]
349
+ var faxNumber: Int ?
350
+ ```
351
+
352
+ ** Not Preferred:**
353
+ ``` swift
354
+ var deviceModels: Array <String >
355
+ var employees: Dictionary <Int , String >
356
+ var faxNumber: Optional <Int >
357
+ ```
358
+
359
+
360
+
340
361
## Control Flow
341
362
342
363
Prefer the ` for-in ` style of ` for ` loop over the ` for-condition-increment ` style.
343
364
344
365
** Preferred:**
345
366
``` swift
346
- for _ in 0 .. 5 {
347
- println (" Hello five times" )
367
+ for _ in 0 ..< 3 {
368
+ println (" Hello three times" )
348
369
}
349
370
350
371
for person in attendeeList {
@@ -354,8 +375,8 @@ for person in attendeeList {
354
375
355
376
** Not Preferred:**
356
377
``` swift
357
- for var i = 0 ; i < 5 ; i++ {
358
- println (" Hello five times" )
378
+ for var i = 0 ; i < 3 ; i++ {
379
+ println (" Hello three times" )
359
380
}
360
381
361
382
for var i = 0 ; i < attendeeList.count ; i++ {
0 commit comments