For easy adding or removing, your "cars
" property should be declared as a NSMutableSet.
And assuming your single Car object is named "listOfCars
", here is one way to do what (I think) you are trying to do:
Model * newModel = [[Model alloc] init];
if(newModel)
{
newModel.picture = [UIImage imageNamed: @"Edsel.jpg"];
newModel.name = @"Ugly Car";
[listOfCars.cars addObject: newModel];
}
And, in your Car .m file, do something like this:
- (id) init
{
self = [super init];
if(self)
{
_cars = [[NSMutableSet alloc] init];
}
return(self);
}
The init method is the only place you should be referring to the underlying variable for your "cars
" property. Everywhere else it should be "listOfCars.cars
" or "self.cars
" if you're referring to the cars set from within the Car object.