在這段代碼中,如果collection
被釋放的類名爲init...
,那麼self.title
或self.managedObjectContext
會發生什麼?我們不需要撥打currentCollection
上的.itemName
而不是collection
本身?使用參數而不保留它?
- (id)initWithCollection:(AACollection *)collection {
if((self = [super initWithNibName:@"AACollectionViewController"
bundle:nil])) {
currentCollection = [collection retain];
self.title = collection.itemName;
self.managedObjectContext = collection.managedObjectContext;
}
感謝
如果在調用這個'init'方法之前已經釋放了'collection',那麼在這個方法中根本不能使用它。它不會在這個方法中釋放,因此引用'currentCollection'或'collection'是等價的。 – trojanfoe 2012-04-10 15:30:01
我建議你閱讀這個http://useyourloaf.com/blog/2011/2/8/understanding-your-objective-c-self.html – 2012-04-10 15:30:41
@trojanfoe:感謝您的快速評論 – Paul 2012-04-10 15:45:29