2014年1月1日 星期三

NSMutableArray 不可作為Class來使用

官方文件上的說明

Subclassing Notes
There is typically little reason to subclass NSMutableArray. The class does well what it is designed to do—maintain a mutable, ordered collection of objects. But there are situations where a custom NSArray object might come in handy. Here are a few possibilities:

Changing how NSMutableArray stores the elements of its collection. You might do this for performance reasons or for better compatibility with legacy code.
Acquiring more information about what is happening to the collection (for example, statistics gathering).
Methods to Override

NSMutableArray defines five primitive methods:

insertObject:atIndex:
removeObjectAtIndex:
addObject:
removeLastObject
replaceObjectAtIndex:withObject:


In a subclass, you must override all these methods. You must also override the primitive methods of the NSArray class.




因為有這些method影響了作為Class的設定,因此需要覆寫原有的method才能使用,否則會產生錯誤。使用上太過麻煩,因此不建議使用NSMutableArray來作為class使用。


沒有留言: