• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
enumerate arrays in Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: enumerate arrays in Swift
      • From: Roland King <email@hidden>
  • Prev by Date: Re: Xcode 5. You can zoom in a storyboard, but not in an XIB? Am I correct here?
  • Next by Date: Re: enumerate arrays in Swift
  • Previous by thread: Re: Unsigned Int in Swift
  • Next by thread: Re: enumerate arrays in Swift
  • Index(es):
    • Date
    • Thread