From the course: Programming Foundations: Design Patterns
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Solution: The Iterator pattern
From the course: Programming Foundations: Design Patterns
Solution: The Iterator pattern
(upbeat music) - [Narrator] For our challenge solution, we chose the Swift programming language. And Swift aggregate objects, like arrays and sets and dictionaries, are all sequences, and they all provide built-in iterators. You can use the for in statement, like we're doing here in the short example, that iterates over an array of animals. Or you can use the underlying iterator supplied by the sequence and use that iterator's interface to iterate. However, most of the time, you'll just use the for in statement.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
(Locked)
Encapsulating iteration1m 44s
-
(Locked)
Understanding the Iterator pattern2m 28s
-
(Locked)
Using the Iterator pattern3m 36s
-
(Locked)
Using built-in iterators1m 19s
-
(Locked)
The single responsibility principle1m 20s
-
(Locked)
The iterator pattern as language feature1m 30s
-
(Locked)
Challenge: The Iterator pattern57s
-
(Locked)
Solution: The Iterator pattern36s
-
(Locked)
-
-