我有一个排序数组,其中包含一系列演讲中所有演讲者的姓名。我已经粘贴了下面的代码,但我的具体问题完全出现在第二个“for”循环中。有多个演示者在 MyClass.speechs 中有多个条目。因此,当我第一次在第二个“for”循环中点击“if”语句时,它的计算结果为真,我看到日志语句“添加了一个演讲……”。然而,第二次它应该评估为真(正如'if'正上方的日志语句所验证的那样),我从来没有看到“添加语音......”行打印到日志中。那么为什么在第一次'item.speaker'和'obj'相同之后我没有输入'if'呢?
[speakers sortUsingSelector:@selector(compare:)];
for (id obj in speakers) {
//now create a unique list of speakers
if ([uniqP containsObject:obj]) {
NSLog(@"already have this object");
}
else {
[uniqP addObject:obj];
//now that we've found a new speaker, we need to go through the entire list of speeches and populate
//them in the correct order.
self.speechesByPresenter = [[NSMutableArray alloc] init];
for (int j=0; j<numEntries; j++) {
SpeechesItem *item = [MyClass.speeches objectAtIndex:j];
NSLog(@" %@--%@--%d (%@)", item.speaker, obj, j, item.title);
if(item.speaker == obj) {
[self.speechesByPresenter addObject:item];
NSLog(@"added a speech, %@ now has %d", item.speaker, [self.speechesByPresenter count]);
}
}
}
}