I have successfully passed the array by reference. However, I want to keep the reference so that I can manage the array in another class.
Subclassing parse and using NSManaged as follows:
class User: PFUser {
// MARK: Managed Properties
@NSManaged private var pets: [Pet]
// MARK: Properties
private(set) lazy var petList: PetList = PetList(user: self, pets: &self.pets)
// non-essentials are omitted
}
And the PetList class:
class PetList {
private var owner: User
private(set) var pets: [Pet]
init(user: User, inout pets: [Pet]) {
self.owner = user
self.pets = pets
}
func appendPet(pet: Pet) {
pet.owner = self.owner
self.pets.append(pet)
}
}
In the init function, I am trying to get the reference to the array. And from there I would like to modify the array in the PetList class (such as in appendPet.
How do I set a variable in the PetList class so that it points to an array in the User class.