Im having problems filtering an array using a predicate. My code is this one:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSError *error;
NSFileManager *fm = [NSFileManager defaultManager];
NSString *filename=[NSString stringWithFormat:@"%@/%lld-%@.jpg",[paths objectAtIndex:0],[TRIP surrogateKey], ms];
NSArray *dirContents = [fm contentsOfDirectoryAtPath:[paths objectAtIndex:0] error:&error];
NSPredicate *fltr = [NSPredicate predicateWithFormat:@"SELF beginsWith %lld-%@",[TRIP surrogateKey], ms];
NSArray *registros=[dirContents filteredArrayUsingPredicate:fltr];
in the debug session i found that i have a problem performing the last line of the code (NSArray *registros=[dirContents filteredArrayUsingPredicate:fltr]) and it gives me the following error:
-[__NSCFString objCType]: unrecognized selector sent to instance 0x7e67200 2013-02-01 16:37:59.132 GastosApp[4462:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objCType]: unrecognized selector sent to instance 0x7e67200'
In the debug section i saw that the memory 0x7e67200 is occupied by the ms variable which is declared:
NSMutableString *ms = [[NSMutableString new] autorelease];
Does anyone see any mistake?
Thanks and regards
May be error because NSPredicate make automatic quotation for format variables like %@.
For example, this:
Will be as:
SELF LIKE[c] "prefix" * "suffix"Right way:
Which give us a correct result:
SELF LIKE[c] "prefix*suffix"