Tag: iteration

iOS: Best Way to do This w/o Calling Method 32 Times?

I’m currently retrieving the Top 100 Scores for one of my leaderboards the following way: – (void) retrieveTop100Scores { __block int totalScore = 0; GKLeaderboard *myLB = [[GKLeaderboard alloc] init]; myLB.identifier = [Team currentTeam]; myLB.timeScope = GKLeaderboardTimeScopeAllTime; myLB.playerScope = GKLeaderboardPlayerScopeGlobal; myLB.range = NSMakeRange(1, 100); [myLB loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error) { if (error != nil) { […]

Does fast enumeration in Objective-C guarantee the order of iteration?

Can I expect it to go from the start of an array to the end in order? Can’t find anything in the docs about this. i.e. is for (id val in array) { NSLog(@”%@”, val); } always going to print out the same as for (int i = 0; i < [array count]; ++i) { […]

Iterating through files in a folder with nested folders – Cocoa

I need to access every file in a folder, including file that exist within nested folders. An example folder might look like this. animals/ -k.txt -d.jpg cat/ -r.txt -z.jpg tiger/ -a.jpg -p.pdf dog/ -n.txt -f.jpg -p.pdf Say that I wanted to run a process on every file within “animals” that isn’t folder. What would be […]

How do I iterate over an NSArray?

I’m looking for the standard idiom to iterate over an NSArray. My code needs to be suitable for OS X 10.4+.

Iterate over two arrays simultaneously

I am new to Swift. I have been doing Java programming. I have a scenario to code for in Swift. The following code is in Java. I need to code in Swift for the following scenario // With String array – strArr1 String strArr1[] = {“Some1″,”Some2”} String strArr2[] = {“Somethingelse1″,”Somethingelse2”} for( int i=0;i< strArr1.length;i++){ System.out.println(strArr1[i] […]

Express for loops in swift with dynamic range

…or how can I use the index inside the for loop condition Hey people Since we’re left with no c style for loops in swift 3 I can’t seem to find a way to express a bit more complex for loops so maybe you can help me out. If I were to write this for(int […]

Using AnyGenerator with Swift 2.2+ (“for in” loop support for custom classes)

Previously I was using the following function to make my custom class conform to the SequenceType protocol: func generate() -> AnyGenerator<UInt32> { var nextIndex = 0 return anyGenerator { if (nextIndex > self.scalarArray.count-1) { return nil } return self.scalarArray[nextIndex++] } } This is a similar implementation to the accepted answers to these two questions: Add […]

Is there a way to iterate over a dictionary?

I know NSDictionaries as something where you need a key in order to get a value. But how can I iterate over all keys and values in a NSDictionary, so that I know what keys there are, and what values there are? I know there is something called a for-in-loop in JavaScript. Is there something […]