Reputation: 3137
I have an NSMutableArray that did its initialisation like follows:
@interface Countries ()
{
NSMutableArray *arrayofCountry;
}
@end
- (void)viewDidLoad
{
//...
arrayofCountry=[[NSMutableArray alloc]init];
//...
}
Then I wanted to apply a removeObjectAtIndex
to that NSMutableArray:
[arrayofCountry removeObjectAtIndex:sourceRow];
The problem is it is crashing with that log:
-[__NSArrayI removeObjectAtIndex:]: unrecognized selector sent to instance
I verified it with:
NSLog( NSStringFromClass( [arrayofCountry class] ));
and it's returning __NSArrayI
.
The question is how it was converted to NSArray?
I'm just populating it with:
arrayofCountry=[JSON valueForKeyPath:@"country_name"];
Thank you for your help.
Upvotes: 1
Views: 272
Reputation: 8607
If the value stored in the JSON file with the key country_name
is an NSArray
then it can't be copied into an NSMutableArray
without changing it. Try doing this:
arrayofCountry = [[JSON valueForKeyPath:@"country_name"] mutableCopy];
Also, when creating your NSMutableArray
create it like this (instead of using alloc and then init):
arrayOfCountry = [NSMutableArray array];
Upvotes: 2
Reputation: 9414
Try this. This will create a new NSMutableArray
based on the contents of your other array.
arrayofCountry = [NSMutableArray arrayWithArray:[JSON valueForKeyPath:@"country_name"]];
Upvotes: 4
Reputation: 8460
try like this,
arrayofCountry=(NSMutableArray *)[JSON valueForKeyPath:@"country_name"];
as @ Ahmed Mohammed:suggested try like this way
arrayofCountry=[[JSON valueForKeyPath:@"country_name"] mutableCopy];
Upvotes: 1