Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems using NSMutableArray

I have created an object of type NSMutableArray

#import <Foundation/Foundation.h>

@interface MyCustomObject : NSMutableArray
{ 
}

@end

in one of my classes, I delcare an instance:

MyCustomObject *myObj = [[NSMutableArray alloc] init];

But xcode is giving a warning on this line: Incompatible pointer types initializing 'MyCustomObject *' with an expression of type 'NSMutableArray *'

Any idea what is wrong? It works fine, but just wondering why it is throwing a warning and how to resolve it?

like image 236
Jesse Avatar asked Aug 10 '26 14:08

Jesse


1 Answers

You can assign a child class to a variable typed as its super-class, but you cannot assign a super-class to a child class variable.

So, you'd want to:

MyCustomObject *myObj = [[MyCustomObject alloc] init];
like image 136
Josh at The Nerdery Avatar answered Aug 13 '26 04:08

Josh at The Nerdery