Here are two simple example of how you could use it.
Lets suppose that you have two different structs Person and Address declared as follows:
struct Address {
let country: String?
}
struct Person {
let name: String
let address: Address?
}
let people = [
Person(name: "Jack", address: nil),
Person(name: "John", address: Address(country: "Finland")),
Person(name: "Jill", address: Address(country: "Nepal"))
]
For first example, you can iterate only those which match certain criteria like below,
for aPerson in people where aPerson.name == "Jack" {
print(aPerson)
}
Notice that address is a optional, you can still use where clause to let it evaluate optional and iterate only those cases like this,
for aPerson in people where aPerson.address?.country == "Finland" {
print(aPerson)
}
Here are other trivial examples on numbers,
let numbers = Array(1...100)
for number in numbers where number % 2 == 0 {
print(number) // prints all even numbers
}