Swift in Depth by Tjeerd in 't Veen

Swift in Depth by Tjeerd in 't Veen

Author:Tjeerd in 't Veen [Tjeerd in 't Veen]
Language: eng
Format: epub
Publisher: Manning Publications
Published: 2018-12-27T16:00:00+00:00


* * *

Join me!

It’s more educational and fun if you can check out the code and follow along with the chapter. You can download the source code at http://mng.bz/7JPy.

* * *

9.1.1. IteratorProtocol

Every time you use a for in loop, you’re using an iterator. For example, you can loop over an array regularly via for in.

Listing 9.1. Using for in

let cheeses = ["Gouda", "Camembert", "Brie"] for cheese in cheeses { print(cheese) } // Output: "Gouda" "Camembert" "Brie"

But for in is syntactic sugar. Actually, what’s happening under the hood is that an iterator is created via the makeIterator() method. Swift walks through the elements via a while loop, shown here.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.