samedi 1 août 2015

Get Quote and it's author SWIFT

I am very new to swift, and I am trying to make an app of quotes, but I want to display the Quote and its own author both in a separate UILabel, Bu I don't know how to do this, because I have a randomQuote function that returns a random index for my array but the array only displays the quote, I want to get a random quote and get the author of the quote.

Here is what I have done so far:

   var quotes = ["'Stay Hungry, Stay Foolish.'", "'Life is what happens while you are busy making other plans.'", ""]

var authors = ["Steve Jobs", "John Lennon"]



func getRandomQuote() -> String{
    //get random index
    var arrayCount = UInt32(quotes.count)
    var randomNumber = arc4random_uniform(arrayCount)
    var finalNumber = Int(randomNumber)

    return quotes[finalNumber]
}

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    var randomImage: String = imageChange[randomNumber]
    self.motivationText.text = getRandomQuote()
    self.imageInspire.image = UIImage(named: randomImage)
}

I was thinking about using a dictionary but I think it won't work :/ Please don't be rude I am very new.




Aucun commentaire:

Enregistrer un commentaire