Skip to content

Commit c7b66af

Browse files
committed
Combine some rules and examples
1 parent 59dcdea commit c7b66af

File tree

1 file changed

+6
-34
lines changed

1 file changed

+6
-34
lines changed

README.markdown

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -301,26 +301,14 @@ func reticulateSplines(spline: [Double], adjustmentFactor: Double,
301301

302302
## Closure Expressions
303303

304-
Use trailing closure syntax wherever possible.
304+
Use trailing closure syntax only if there's a single closure expression parameter at the end of the argument list. Give the closure parameters descriptive names.
305305

306306
**Preferred:**
307307
```swift
308308
UIView.animateWithDuration(1.0) {
309309
self.myView.alpha = 0
310310
}
311-
```
312-
313-
**Not Preferred:**
314-
```swift
315-
UIView.animateWithDuration(1.0, animations: {
316-
self.myView.alpha = 0
317-
})
318-
```
319311

320-
However, avoid trailing closure syntax when using a method that contains multiple closures.
321-
322-
**Preferred:**
323-
```swift
324312
UIView.animateWithDuration(1.0,
325313
animations: {
326314
self.myView.alpha = 0
@@ -333,34 +321,18 @@ UIView.animateWithDuration(1.0,
333321

334322
**Not Preferred:**
335323
```swift
324+
UIView.animateWithDuration(1.0, animations: {
325+
self.myView.alpha = 0
326+
})
327+
336328
UIView.animateWithDuration(1.0,
337329
animations: {
338330
self.myView.alpha = 0
339-
}) { finished in
331+
}) { f in
340332
self.myView.removeFromSuperview()
341333
}
342334
```
343335

344-
**Also Not Preferred:**
345-
346-
Note that this how Xcode will indent the code when using Ctrl-I
347-
348-
```swift
349-
UIView.animateWithDuration(1.0, animations: {
350-
self.myView.alpha = 0
351-
}) { finished in
352-
self.myView.removeFromSuperview()
353-
}
354-
```
355-
356-
In all cases, give the closure parameters descriptive names.
357-
358-
```swift
359-
return SKAction.customActionWithDuration(effect.duration) { node, elapsedTime in
360-
// more code goes here
361-
}
362-
```
363-
364336
For single-expression closures where the context is clear, use implicit returns:
365337

366338
```swift

0 commit comments

Comments
 (0)