Tag: iteration

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 […]