Skip to content

Commit b90fa5f

Browse files
committed
Merge modified changes about closures
source: jawwad/improve-trailing-closure-guideline
2 parents 909496b + 43530f8 commit b90fa5f

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

README.markdown

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,35 @@ func reticulateSplines(spline: [Double], adjustmentFactor: Double,
301301

302302
## Closure Expressions
303303

304-
Use trailing closure syntax wherever possible. In all cases, give the closure parameters descriptive names:
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

306+
**Preferred:**
306307
```swift
307-
return SKAction.customActionWithDuration(effect.duration) { node, elapsedTime in
308-
// more code goes here
308+
UIView.animateWithDuration(1.0) {
309+
self.myView.alpha = 0
310+
}
311+
312+
UIView.animateWithDuration(1.0,
313+
animations: {
314+
self.myView.alpha = 0
315+
},
316+
completion: { finished in
317+
self.myView.removeFromSuperview()
318+
}
319+
)
320+
```
321+
322+
**Not Preferred:**
323+
```swift
324+
UIView.animateWithDuration(1.0, animations: {
325+
self.myView.alpha = 0
326+
})
327+
328+
UIView.animateWithDuration(1.0,
329+
animations: {
330+
self.myView.alpha = 0
331+
}) { f in
332+
self.myView.removeFromSuperview()
309333
}
310334
```
311335

@@ -525,6 +549,7 @@ Smiley faces are a very prominent style feature of the raywenderlich.com site! I
525549

526550
This style guide is a collaborative effort from the most stylish raywenderlich.com team members:
527551

552+
* [Jawwad Ahmad](https://github.com/jawwad)
528553
* [Soheil Moayedi Azarpour](https://github.com/moayes)
529554
* [Scott Berrevoets](https://github.com/Scott90)
530555
* [Eric Cerney](https://github.com/ecerney)

0 commit comments

Comments
 (0)