I’m trying to create a predicate to sort an array of objects that have a date property. However, when I try to NSLog the predicate, an exception is raised and I get a strange error.
Here’s the code:
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy"];
NSDate * minDate = [dateFormatter dateFromString:@"2011"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"date >= %@ ", minDate];
NSLog(predicate);
Here’s the error:
2012-02-04 12:45:58.400 MyApp[42746:17303] -[NSComparisonPredicate length]: unrecognized selector sent to instance 0x9359000
So, why is this happening and how can I fix it?
try:
NSLog(@"%@", predicate)NSLog expects a NSString, that works as an format string. The number of format specifiers in the format string will specify, how many arguments need to follow.
from the doc: