Skip to content

Commit 3a025ef

Browse files
committed
2 parents 9b36dac + 9932802 commit 3a025ef

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

README.markdown

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Writing Objective-C? Check out our [Objective-C Style Guide](https://github.com/
2121
* [Constants](#constants)
2222
* [Optionals](#optionals)
2323
* [Type Inference](#type-inference)
24+
* [Syntactic Sugar](#syntactic-sugar)
2425
* [Control Flow](#control-flow)
2526
* [Use of Self](#use-of-self)
2627
* [Smiley Face](#smiley-face)
@@ -238,15 +239,15 @@ class BoardLocation {
238239
Keep short function declarations on one line including the opening brace:
239240

240241
```swift
241-
func reticulateSplines(spline: Double[]) -> Bool {
242+
func reticulateSplines(spline: [Double]) -> Bool {
242243
// reticulate code goes here
243244
}
244245
```
245246

246247
For functions with long signatures, add line breaks at appropriate points and add an extra indent on subsequent lines:
247248

248249
```swift
249-
func reticulateSplines(spline: Double[], adjustmentFactor: Double,
250+
func reticulateSplines(spline: [Double], adjustmentFactor: Double,
250251
translateConstant: Int, comment: String) -> Bool {
251252
// reticulate code goes here
252253
}
@@ -337,14 +338,34 @@ var currentBounds: CGRect = computeViewBounds()
337338
**NOTE**: Following this guideline means picking descriptive names is even more important than before.
338339

339340

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+
340361
## Control Flow
341362

342363
Prefer the `for-in` style of `for` loop over the `for-condition-increment` style.
343364

344365
**Preferred:**
345366
```swift
346-
for _ in 0..5 {
347-
println("Hello five times")
367+
for _ in 0..<3 {
368+
println("Hello three times")
348369
}
349370

350371
for person in attendeeList {
@@ -354,8 +375,8 @@ for person in attendeeList {
354375

355376
**Not Preferred:**
356377
```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")
359380
}
360381

361382
for var i = 0; i < attendeeList.count; i++ {

0 commit comments

Comments
 (0)