I want to create a subclass of NSMutableArray and need to override the -initWithObjects: method.
But How to call [super xxx];?
- (id) initWithObjects:(id)firstObj, ... {
[super initWithObjects:firstObj]; // Error: Missing sentinel in method dispatch
// Error: The result of a delegate init call must be immediately returned or assigned to "self"
}
Thanks.
You can’t. As discussed in the documentation for
NSArray:So you can assign
self = [super init];and add the objects from your initialiser to the resulting object. Indeed, because of the way thatNSArrayis implemented, calling any-initWith…method is likely to return an instance of a differentNSArraysubclass.Notice that the documentation also discusses alternatives to subclassing
NSArraythat may be easier, more reliable or better in some other way.