Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

grandM

macrumors 68000
Original poster
Oct 14, 2013
1,551
309
I was fumbling around with an own class. I tried to let the class keep an array of all objects created with that class. For instance
Code:
class Wife {
var id: UInt
var existingWives:[Wife]?
init(){
if let _ = self.existingWives {
self.id = UInt(self.existingWives!.count) + 1
self.existingWives!.append(self)
} else {
self.id = 1
self.existingWives = [self]
}
}
}
This doesn't work though? Or is it a no go to enter an array of its owns objects within the class?
 
I solved it. Putting static before the array var made it a class variable. Not sure though if an class should hold an array of its own instances.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.