我有一个字符串数组.
我怎样才能弄清楚字符串在数组中的索引?
我如何枚举包含多种类型对象的NSArray,以获取找到NSString的所有索引,然后能够通过说出类似的内容来按顺序引用每个索引...
NSString *firstOccurrence = [myArray objectAtIndex:firstOccurrence];
NSString *secondOccurrence = [myArray objectAtIndex:secondOccurrence];
NSString *thirdOccurrence = [myArray objectAtIndex:thirdOccurrence];
Run Code Online (Sandbox Code Playgroud)
谢谢!
编辑:我如何使用代码(更新@NJones示例.)
我需要字符串存储在数组中的索引的Integer值,以使用该值更新NSUInteger属性"wordDisplayed".
在我的代码中,我使用UIActionSheet的修改版本来接受块:https: //github.com/zoul/Lambda-Alert
NSIndexSet *stringLocations = [arrayInLesson indexesOfObjectsPassingTest:^(id obj, NSUInteger idx, BOOL *stop){
return [(NSObject *)obj isKindOfClass:[NSString class]];
}];
NSArray *passingObjects = [arrayInLesson objectsAtIndexes:stringLocations];
sectionHeadersAct = [[LambdaSheet alloc] initWithTitle:@"Book 2 Lesson 1"];
[sectionHeadersAct addButtonWithTitle:@"D. E. F. & G. Teach New Letters" block:^{
//Do nothing yet
}];
[sectionHeadersAct addButtonWithTitle:[passingObjects objectAtIndex:0] block:^{
NSLog(@"First");
wordDisplayed = theIndexOfThisStringIn_arrayInLesson;
}];
[sectionHeadersAct addButtonWithTitle:[passingObjects objectAtIndex:1] block:^{
NSLog(@"Second"); …Run Code Online (Sandbox Code Playgroud)