I am trying to remove any elements from an NSMutableArray object that contain a SPACE using the following:
[searchCriteria removeObject:[NSString stringWithString:@" "]];
I get the exception “-[__NSArrayI removeObject:]: unrecognized selector sent to instance”. What am I doing wrong?
EDIT:
OK, so I tried the following
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"SELF NOT CONTAINS ' '"];
NSArray *nonEmptyElements = [searchCriteria filteredArrayUsingPredicate: predicate];
and get the error Unable to parse the format string “SELF NOT CONTAINS ‘ ‘”‘
How do I specify an empty string after the CONTAINS?
You have a plain NSArray rather than an NSMutableArray. Probably at some point the NSMutableArray you thought you had was copied or serialized, resulting in an immutable array.
Incidentally, as Lefteris says, this will filter out strings consisting only of a single space. To filter out any string that has a space anywhere in it, you’ll want to do it the way he says. And if you do want to filter out single-space strings, it’s simpler just to write
@" "instead of[NSString stringWithString:@" "]— it’s precisely equivalent.