我正在通過我的表中的ChecklistItem
實體進行枚舉,以查看哪些人具有priority
(NSNumber屬性)爲1. checklistItems
與Checklist
處於多對多關係。爲什麼這個簡單的'if'語句不工作(在快速枚舉中)?
在這個簡單的代碼中,第一個NSLog工作正常,並報告我的幾個ChecklistItems的優先級爲1.但是第二個NSLog永遠不會被調用。爲什麼是這樣?我假設我正在構思錯誤的「如果」陳述,但我不知道如何。
for (ChecklistItem *eachItem in checklist.checklistItems){
NSLog(@"Going through loop. Item %@ has priority %@.", eachItem.name, eachItem.priority);
if (eachItem.priority == [NSNumber numberWithInt:1]) {
NSLog(@"Item %@ has priority 1", eachItem.name);
}
}
這是行不通的,eachItem.priority是一個NSNumber – MarkPowell 2011-04-14 16:34:15
但我讀過NSNumber有 - (int)intValue方法嗎?文檔中有什麼問題嗎?請提一下。 – Ravin 2011-04-14 16:36:49
我的錯誤,應該仔細閱讀。錯過了你的「intValue」。 – MarkPowell 2011-04-14 16:41:18