2012-02-04 86 views
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 

那麼,爲什麼會出現這種情況以及如何解決呢?

+0

什麼是你想要的謂詞適用於財產的確切類型? – Costique 2012-02-04 19:57:52

+0

NSDate。但是,我甚至沒有去實際使用謂詞的地方。 – 2012-02-04 19:59:56

+0

我不確定比較NSDates與這樣的謂詞將工作。是的,你不能像這樣使用NSLog()。 – Costique 2012-02-04 20:06:20

回答

2

嘗試:NSLog(@"%@", predicate)

NSLog的期望一個的NSString,該工程作爲格式字符串。格式字符串中的格式說明符數將指定需要遵循多少個參數。

doc

NSLog
Logs an error message to the Apple System Log facility.

void NSLog (
    NSString *format, 
    ... 
); 

Discussion
Simply calls NSLogv, passing it a variable number of arguments.