Array by Swift parameter

Asked

Viewed 311 times

2

Good afternoon guys all right?

how do I pass an array per parameter? and 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
}

Thanks friends!

  • Your functions should be named starting with a lowercase letter.

  • You need to pass the array type func startGame(teste: [String]?) -> String {

  • I still have error in the parameter

  • Edit your question and put your code and the error that is giving

1 answer

3


To pass a array, just you put the type of it, optional add case ?

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
}
  • pass a parameter to a function or method without even using it makes no sense

  • I figured that out, but I guess it was just for his learning, you’ll know ...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.