This is a newbie question. I have an object that looks like the following (e.g. MyObject.h
).
#import <Foundation/Foundation.h>
#import "JSONModel.h"
@protocol MyObject
@end
@interface MyObject : JSONModel
@property (strong,nonatomic) NSString* name;
@end
And the implementation looks like the following (e.g. MyObject.m
).
#import "MyObject.h"
@implementation MyObject
@end
In my code elsewhere, I then define a NSMutableArray
as follows.
NSMutableArray<MyObject>* list;
list = [[NSMutableArray alloc] init];
And I get this warning.
Incompatible pointer types assigning 'NSMutableArray<MyObject> ' from 'NSMutableArray'
I know from generics aren't supported out-of-the-box by Objective-C for collections (and that is not what I am trying to do here either), but my NSMutableArray
is defined with such a protocol MyObject
because I am trying to follow the examples from "JSONModel's" GitHub page.
The code still compiles, but with the warning above. How do I
- make the warning go away, or
- allocate/initialize
NSMutableArray
correctly?
Update:
I continued to search how to get rid of that warning, and it turns out if I create a NSMutableArray
like the following, the warning goes away (and project compiles without errors). I will write a unit test and see if it works as expected.
list = (id)[NSMutableArray new];