in this code, if collection is released in the class that called init..., what will happen to self.title or self.managedObjectContext? Don’t we have to call .itemName on currentCollection rather than on collection itself?
- (id)initWithCollection:(AACollection *)collection {
if( (self = [super initWithNibName:@"AACollectionViewController"
bundle:nil]) ) {
currentCollection = [collection retain];
self.title = collection.itemName;
self.managedObjectContext = collection.managedObjectContext;
}
Thanks
You’re retaining
collection, so nothing bad will happen. That said, it’s generally a good idea to give your string propertiescopysemantics. For example, assumingtitleis a string property, ifcollection.itemNamehappens to give you a mutable string, you really want to make an immutable copy of it so that it won’t be changed right under your nose (which could happen if you just reference the mutable string). Usingcopywill do that for you.No.
currentCollectionandcollectionwill point to the same object. It’s the object that’s retained, not the pointer. Some might consider it better style to usecurrentCollection, but it’s effectively the same thing either way.