Member-only story

Iterator Design Pattern in Swift Universe

An unnoticed behavioral pattern in detail.

Nikita Lazarev-Zubov
5 min readFeb 24, 2019

Iterator is one of the design patterns which often stay unnoticed by programmers because its implementation details are usually already embedded in the programming language’s standard library. However, it’s also one of behavioral patterns described in a Gang of Four (GoF) classical book “Design Patterns: Elements of Reusable Object-Oriented Software”. Its comprehension won’t never be redundant and might be helpful.

Photo by Glenn Carstens-Peters on Unsplash

Iterator is a way to provide serial access to all elements of a composite object (usually, a container type, such as array and set).

Built-In Features

Create an array:

let numbersArray = [0, 1, 2]

…and iterate it with a loop:

for number in numbersArray {
print(number)
}

…are very common things to do, especially for modern programming languages, such as Swift. Nevertheless, this feature is backed by code which implements the Iterator design pattern.

--

--

Nikita Lazarev-Zubov
Nikita Lazarev-Zubov

Written by Nikita Lazarev-Zubov

Swift and general programming topics, Agile software development, soft skills

No responses yet