0
我想創建一個謂詞來排序具有日期屬性的對象數組。但是,當我嘗試NSLog謂詞時,會引發異常,並且出現一個奇怪的錯誤。記錄時非常奇怪的NSPredicate行爲
下面的代碼:
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy"];
NSDate * minDate = [dateFormatter dateFromString:@"2011"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"date >= %@ ", minDate];
NSLog(predicate);
這裏的錯誤:
2012-02-04 12:45:58.400 MyApp[42746:17303] -[NSComparisonPredicate length]: unrecognized selector sent to instance 0x9359000
那麼,爲什麼會出現這種情況以及如何解決呢?
什麼是你想要的謂詞適用於財產的確切類型? – Costique 2012-02-04 19:57:52
NSDate。但是,我甚至沒有去實際使用謂詞的地方。 – 2012-02-04 19:59:56
我不確定比較NSDates與這樣的謂詞將工作。是的,你不能像這樣使用NSLog()。 – Costique 2012-02-04 20:06:20