March 2017
Intermediate to advanced
226 pages
5h 13m
English
Swift offers helpful ways to optimize the way you interact with collections. Here are some tips and pointers about collections that you may want to adopt into your preferred practices.
Avoid indices when you can iterate across a slice. This transfers complexity from the body to the loop declaration, creating cleaner implementations:
| | for value in array[2...5] { f(value) } // yes |
| | |
| | for index in 2...5 { f(array[index]) } // no |
Slices are great for iterating and creating subcollections, but a tiny ArraySlice can be backed by a much larger array. Don’t hold onto slices any longer than you need to. When you require access for significant periods of time, convert ...
Read now
Unlock full access