jeudi 25 février 2016

Update multiple labels with values from a dictionary?

I'm trying to make an app that will select an index at random, something like 0-1000 and then print the key, value, and link of the selected number to three seperate labels on the iPhone simulator.

So from my example, I want to randomly select "0" or "1" and if for instance "1" was chosen; then the key, value, and link information would each be printed to three separate labels on the simulator. The following is what I've been working on in playgrounds. Is there a better way to go about this?

var spDictionary: [String: [String:String]] = [

    "0": ["key": "AMZN", "value": "AMAZON", "link": "yahoo"],
    "1": ["key": "AAPL", "value": "APPLE", "link": "yahoo2"],

]

And for the random aspect I think it would be something like this but I'm not sure? Sorry for the newbie question.

let randomIndex: Int = Int(arc4random_uniform(UInt32(spDictionary.count)))`




Aucun commentaire:

Enregistrer un commentaire