March 2017
Intermediate to advanced
226 pages
5h 13m
English
Swift tuples offer a powerful and often overlooked styling feature in Swift. They enable you to collect related items and apply them in simultaneous statements. For example, you might consider using tuples to declare connected variables using a single line, as in the following code:
| | var (x, y) = (20, 50) // x: Int is 20, y: Int is 50 |
| | var (x, y): (Int, Int) = (20, 50) // ditto |
This compact presentation establishes a parallel between the two symbols and provides a coherent elegance that isn’t quite matched by the alternatives:
| | var x: Int = 20 // fine, boring |
| | var y: Int = 20 |
| | |
| | var x = 20, y = 20 // ditto |
| | |
| | var x = 20; var y = 50 // a little ugly |
Tuples parallelize the way you lay out assignments. ...
Read now
Unlock full access