I would like to create an object array as a property of another class in Swift, such as:
class person{
var livingInHouse : house
name : String
}
class house{
var personArray : [person]
}
My constraints are:
- I would like to easily access the objects in the personArray using subscripts: e.g.
houseInstance.personArray[1].name = "Steve"
- I would like to create the
personArray
so that theperson
objects are deallocated whenhouseInstance
object is deallocated. What is the best method in Swift to do this?