Note that there are some explanatory texts on larger screens.

plurals
  1. POEnumerate NSArray using blocks to find and store all indexe's of all NSStrings in array
    primarykey
    data
    text
    <p>How could I enumerate an NSArray containing objects of multiple types, to get all the indexes where an NSString is found, then be able to refer to each index in order by saying something like... </p> <pre><code>NSString *firstOccurrence = [myArray objectAtIndex:firstOccurrence]; NSString *secondOccurrence = [myArray objectAtIndex:secondOccurrence]; NSString *thirdOccurrence = [myArray objectAtIndex:thirdOccurrence]; </code></pre> <p>Thanks!</p> <p>EDIT: How I'm using the code (Updated with @NJones example.)</p> <p>I need the Integer value of the index where the strings are stored in the array, to update the NSUInteger property "wordDisplayed" with that value.</p> <p>In my code here, I'm using a modified version of UIActionSheet to accept blocks: <a href="https://github.com/zoul/Lambda-Alert" rel="nofollow">https://github.com/zoul/Lambda-Alert</a> </p> <pre><code>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. &amp; 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"); wordDisplayed = theIndexOfThisStringIn_arrayInLesson; }]; [sectionHeadersAct addButtonWithTitle:[passingObjects objectAtIndex:2] block:^{ NSLog(@"Third"); wordDisplayed = theIndexOfThisStringIn_arrayInLesson; }]; [sectionHeadersAct addButtonWithTitle:[passingObjects objectAtIndex:3] block:^{ NSLog(@"Fourth"); wordDisplayed = theIndexOfThisStringIn_arrayInLesson; }]; [sectionHeadersAct setDismissAction:^{ //Do nothing yet }]; [sectionHeadersAct showInView:self.view]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload