• 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
Re: enumerate arrays in Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: enumerate arrays in Swift


  • Subject: Re: enumerate arrays in Swift
  • From: Roland King <email@hidden>
  • Date: Wed, 02 Jul 2014 21:08:54 +0800

That's in the book, look at the enumerate() function which returns the tuples required to give you (index,element)

On 2 Jul, 2014, at 9:01 pm, Gerriet M. Denkmann <email@hidden> wrote:

> 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


 _______________________________________________
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


References: 
 >enumerate arrays in Swift (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: enumerate arrays in Swift
  • Next by Date: Shifting in Swift
  • Previous by thread: enumerate arrays in Swift
  • Next by thread: Shifting in Swift
  • Index(es):
    • Date
    • Thread