December 2018
Intermediate to advanced
414 pages
10h 19m
English
Starting with Swift 3, C-style statements that are usually used when iterating through arrays have been removed, so you can no longer write the following:
for var i = 0; i < otherDoubles.count; i++ { let element = otherDoubles[i]}
Instead, we use more powerful syntax:
A simple iterator is as follows:
for value in doubles { print("\(value)") // 1.0, 2.0, 3.0}
You can use an enumerator as follows:
for (idx, value) in doubles.enumerated() { print("\(idx) -> \(value)") // 0 -> 1.0, 1 -> 2.0, 2 -> 3.0}
Similarly, you can use the forEach method that will invoke a closure for each element, passing it as the first parameter:
doubles.forEach { value in // do something with the value}
Next, we can transform the current ...
Read now
Unlock full access