3

Why I can't use index from FromEach as index for other array. This index is Int, so what's the problem?

var word: String{
    return slova[selector]
}

var symbols: Array<Character>{
    return [Character](word)
}

var body: some View {
    HStack{
        ForEach(0..<word.count-1){index in
            Button("\(symbols[index])") {

            }

        }

    }
}

result: bug in "Button("(symbols[index])") {" :Instance method 'appendInterpolation' requires that 'Character' conform to '_FormatSpecifiable'

1
  • Use String.init instead of interpolation, so Replace Button("(symbols[index])") with Button(String(self.symbols[index])) Commented Mar 26, 2020 at 8:25

1 Answer 1

2

The error is not due index, but about string generation, use instead

    ForEach(0..<word.count-1){index in
        Button(String(self.symbols[index])) { // << here !
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.