靜態分析錯誤解析

1.Property of mutable type 'NSMutableArray' has 'copy' attribute; an immutable object will be stored instead;

**Exam** : @property (nonatomic, copy) NSMutableArray *coursesArray;

**Reason:**

defined:@property (copy, nonatomic) NSMutableArray *words;

NSArray *fixedWords = @[@"One",@"Two", @"Three", @"Four", @"Five", @"Six", @"Seven", @"Eight"];

NSMutableArray *mutableWords = [[NSMutableArray alloc] initWithArray:fixedWords];

self.words = mutableWords;

[self.words removeOjbectAtIndex:2];

這時候會出錯:unrecoginzed selector sent to instance;

copy 通常會返回不可變的副本。

因此,當一個NSMutableArray設置copy,會返回一個NSArray類型的包含同樣數據的結構。

此處建議用strong來修飾mutableArray.

說到這里 就得提一下copy 、 mutableCopy 以及strong的區別。關于copy 、mutableCopy 、strong三者間的關系

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容