Chris Hardaker
Chris Hardaker

Reputation: 93

Why do I get a warning about NSMutableArray incompatible pointer type?

I receive a simple text string on my iPad and I am trying to simply parse this into a table view, but I get the following warning:

"Incompatible pointer type assigning to 'NSMutableArray*' from 'NSArray'"

So, controller.h

NSMutableArray *homeData;
@property (nonatomic, retain) NSMutableArray *homeData;

then, controller.m

@synthesize homeData;

followed by

[searchData appendData:data];
NSString *searchString = [[NSString alloc] initWithData:searchData encoding:NSUTF8StringEncoding];
NSArray *sectionString = [searchString componentsSeparatedByString:@";;"];
homeData = [[[sectionString objectAtIndex:0] componentsSeparatedByString:@";"] retain];

(data = 'no_home;;no_locl;;no_natl;;9:CHardaker;;')

Under normal circumstances, the string will hold a list of index numbers and abbreviated names, up to 100.

I get the warning on the final homeData line. I would expect that homeData objectAtIndex:0 should be no_home, however it is not and this is the only issue outstanding in the execution.

Upvotes: 2

Views: 3599

Answers (1)

mipadi
mipadi

Reputation: 410742

componentsSeparatedByString: returns an NSArray, not an NSMutableArray. If you want the mutable variant, change the last line to:

homeData = [[[sectionString objectAtIndex:0] componentsSeparatedByString:@";"] mutableCopy];

Upvotes: 10

Related Questions