vendredi 19 février 2016

How to localize random text swift

Complete newbie here though have searched through all the files on here and googled extensively and still can't work it out, so here goes.

I have this in a model.swift file (together with the answers array)

    func getAnswer() -> String {
    var random = Int(arc4random_uniform(UInt32(answers.count)))

    let result = answers[random]
    return result
}

and this in my view controller

@IBAction func getAnswerTapped(sender: AnyObject) {

    answerText.text = model.getAnswer()
    answerText.text = NSLocalizedString("Of course I do...",comment: "")
   answerText.hidden = false

}

This is accessing the localizable.string file as it translates the phrase correctly when I run the app though I can't work out how to localize the randomly generated phrase from the answers array listed in the model.swift file.

What should this line be to do that?

answerText.text = NSLocalizedString("Of course I do...",comment: "")

Thank you. Nicola




Aucun commentaire:

Enregistrer un commentaire