Swift 3 - Making class iterable

Viewed 2356

Consider my two classes:

// Person.swift
class Person {
    var parents: Parents?
    // ...
}

// Parents.swift. Only a collection of parents with some helper methods.
class Parents {
    var parents = [Person]()
    // ...
}

How could I make Parents iterate in a for loop using the iterators of parents. This is not a real world app. I'm just curious. Just would like to use for parent in myParents instead of for parent in myParents.parents.

1 Answers
Related