I have NSMutableArray initialised and populated with NSString objects in AppDelegate.m from sqlite database. Now I've setup that AppDelegate in my View Controller :
appDelegate = (IBUAppDelegate *)[[UIApplication sharedApplication] delegate];
so I can access my NSMutableArray objects like this:
[appDelegate.myNonSortedArray objectAtIndex:row];
Now I have created one NSMutable array in my @interface part of my View Controller so I can populate it with sorted NSString objects from my NSMutableArray from AppDelegate.m.
@interface IBULanguageViewController ()
{
IBUAppDelegate *appDelegate;
NSMutableArray *myArraySorted;
}
@end
Then I tried to populate myArraySorted using sorted NSStrings from my NSMutableArray from AppDelegate.m in - (void)viewDidLoad method in my View Controller, so I can access sorted array during creation of cells in my Table View Controller.
- (void)viewDidLoad
{
[super viewDidLoad];
appDelegate = (IBUAppDelegate *)[[UIApplication sharedApplication] delegate];
myArraySorted = [[NSMutableArray alloc] init];
[myArraySorted addObjectsFromArray:[appDelegate.myNonSortedArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]];
}
and I get [NSNull localizedCaseInsensitiveCompare:]: unrecognized selector sent to instance 0x1a51068.
NSNullwhich doesn't respond to the selector (at least that's what the error message says!)nullvalue. I have got rid of them by usingif(![someRecord isEqualToString:@"(null)"]), so that I can addsomeRecordto myNSMutableArray. As far as I can see there is noNSNullin my array. How can I check that?someRecordgenuinely is anNSNullthen then that check won't work becauseNSNulldoesn't respond to[someRecord isEqualToString:@"(null)"]intend to check if the value is anNSNullyou'd doif (![someRecord isKindOfClass:[NSNull class]]). If there aren't too may records then you could log the array to check this, i.eNSLog (@"unsorted: %@", appDelegate.myNonSortedArray);theNSNulls will be printed (null) to the console (or you could examine the array in the debugger by adding a breakpoint at a relevant location.someRecordgets populated with(null)string value if its value in sqlite database isnull. If I use[someRecord isEqualToString:@"(null)"]and I log it, I can't see any null records. But still I can't sort it. Maybe I need to use some sqlite function?localizedCaseInsensitiveCompare:. It won't work on an NSNull, and that is what it isn't being called on. You may not want @"(null)" in your array but that won't stop it working. Any instance of NSNull needs to be removed from the arrayappDelegate.myNonSortedArraybefore you callsortedArrayUsingSelector:on it. If they've all been removed then you won't get this error message.