Array per swift parameter

0

Good afternoon guys, how are you?

How do I pass an array per parameter? and I would like the array parameter to be optional

Example:

func startGame(teste: Array) -> String {


    let randomIndex = Int(arc4random_uniform(UInt32(wordHard.count)))
    let word = wordHard[randomIndex]

    // verificando se existe palavra atribuida a variavel
    if currentWord == "" {
        currentWord = word
        infoHelp.text = wordHardHelp[randomIndex]
    }
    return word
}

Thank you friends!

    
asked by anonymous 24.01.2016 / 19:55

1 answer

1

To pass a array , simply put the type of it, if optional add ?

func startGame(teste: [Int]?) -> String {


    let randomIndex = Int(arc4random_uniform(UInt32(wordHard.count)))
    let word = wordHard[randomIndex]

    // verificando se existe palavra atribuida a variavel
    if currentWord == "" {
        currentWord = word
        infoHelp.text = wordHardHelp[randomIndex]
    }
    return word
}
    
26.01.2016 / 20:09