I am trying to create an NSPredicate that searches through an array, then checks to see whether any objects in that array start with other string. Here is my code. It gave me a crash, so apparently something is wrong.
array = [[NSArray alloc] initWithObjects:@"Hello", @"What", @"Maybe", nil]; NSString *string = @"H"; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%@ BEGINSWITH %@", string, array]; NSArray *filteredArray = [array filteredArrayUsingPredicate:predicate]; NSLog(@"%@", filteredArray);
Here is the crash error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't do a substring operation with something that isn't a string (lhs = H rhs = ( Hello, What, Maybe ))'
It then gave a bunch of numbers in the error, I can post that if you'd like, just let me know.