1

Long time reader. First-time question from a beginner trying to learn Swift. This is a total noob-level question, but I haven't been able to find an answer, so I apologize in advance for my own stupidity and the simplicity of this question.

I am trying to pass an array into a function, but I get the following error: Cannot convert value of type '[String].Type' to expected type '[String]'.

func confirmAndSend() {
    startTitleInstructions.text = "confirm and send your survey"
    confirmStackView.isHidden = false
    populateConfirmStack(attributesChosen: [String])
}

func populateConfirmStack(attributesChosen: [String]) {
    confirmLabel1.text = attributesChosen[0]
    confirmLabel2.text = attributesChosen[1]
    confirmLabel3.text = attributesChosen[2]
    confirmLabel4.text = attributesChosen[3]
    confirmLabel5.text = attributesChosen[4]
}

The attributesChosen argument was defined as an empty Array, type String, and it was populated by users choosing up to five options, that were appended to the empty Array. What I am trying to do in this step is confirm the attributes chosen, by displaying the five options selected earlier.

I've tried several different approaches on how to word and structure it, following other examples with Int I have seen listed here, but nothing has worked for me. This seems like it should be very easy, and I'm guessing it is an obvious syntax mistake, one of which I have not been able to sort out on my own.

Thanks for the help!

4
  • In confirmAndSend() you have to pass the actual array containing the 5 items not the type of the array. Commented May 2, 2018 at 20:05
  • I still get an error (undeclared type) - I'm guessing I'm still doing something very obviously wrong; can I ask you clarify it a bit more? Commented May 2, 2018 at 20:17
  • You have to pass the object which was populated by users choosing up to five options. It's not part of the code. Commented May 2, 2018 at 20:20
  • Suppose you're hungry for a snack. Which would be more appealing for you to eat: a banana, or the concept of a banana? The compiler feels the same way about [String]. Commented May 2, 2018 at 21:29

1 Answer 1

1

You are sending array of type , which should be array of string values ["a", "b"]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.