enumerate arrays in Swift
enumerate arrays in Swift
- Subject: enumerate arrays in Swift
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Wed, 02 Jul 2014 20:01:58 +0700
enumerateKeysAndObjectsUsingBlock: can be written as:
var airports = ["TYO": "Tokyo", "DUB": "Dublin"]
for (airportCode, airportName) in airports
{
println("\(airportCode) = \(airportName)")
}
But how to do NSArray's enumerateObjectsUsingBlock: ?
This works, but is rather clumsy:
let names = ["Anna", "Alex", "Brian", "Jack"]
var i : Int = 0
for name in names
{
let indexFormated = NSString(format: "-", i++)
println( "name[" + indexFormated + "] = " + name)
}
What I want is:
for (idx, name) in names {...}
Can this be done in Swift?
Gerriet.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden