我正在通过我的表中的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