1. @property (copy) NSMutableArray *array; 這樣寫有什么問題嗎?
因為用了copy, 內(nèi)部會深拷貝一次, 指針實際指向的是NSArray, 所以如果調(diào)用removeObject和addObject方法的話, 會unRecognized selector?
-copy, as implemented by mutable Cocoa classes, alwaysreturns their immutable counterparts. Thus, when an NSMutableArray is sent -copy, it returns an NSArray containing the same objects.
Becausewordshas the memory qualifiercopy, this line:
NSMutableArray *mutWords = [[NSMutableArray alloc] initWithArray:fixedWords];
self.words = mutWords;
Expands out to:
NSMutableArray *mutWords = [[NSMutableArray alloc] initWithArray:fixedWords];
self.words = [mutWords copy];
Given that NSMutableArray is a subclass of NSArray, the compiler doesn't complain, and you now have a ticking time bomb on your hands because NSArray does not recognize it's mutable subclass' methods (because it cannot mutate it's contents).