我想反转一个句子,但我不知道如何在快速枚举中正确获取下一个对象而没有任何问题:/
- (NSString *) reverseWords
{
NSString *result = [[NSString alloc] init];
NSArray *tab_words = [self componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSEnumerator *reversed = [tab_words reverseObjectEnumerator];
for (NSString *word in reversed)
{
result = [result stringByAppendingString:word];
// Bug here
if ([reversed nextObject])
result = [result stringByAppendingString:@" "];
}
return (result);
}
谢谢你