0
NSEnumerator* friendsEnumerator = [friends objectEnumerator];

id aFriend;

while ((aFriend = [friendsEnumerator nextObject])) {

  printf("%s\n", [aFriend UTF8String]);

}


int friendsCount = [friends count];

for(int i = 0; i < friendsCount; i++) {

  printf("%s\n", [[friends objectAtIndex: i] UTF8String]);

}


for(NSString* aFriend in friends) {

  printf("%s\n", [aFriend UTF8String]);

}
4

3 に答える 3

2

以下のメソッドを使用して配列を列挙することもできます。 stop パラメータは、ブロック内で決定された条件に基づいて列挙を早期に停止できるため、パフォーマンスにとって重要です。

[friends enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop){

 if ('some condition') {
      NSLog(@"Object Found: %@ at index: %i",obj, index);
      *stop = YES;
 }

} ];
于 2013-10-01T11:25:22.443 に答える