Tema Sysoev
Tema Sysoev

Reputation: 61

Using index from ForEach in other array

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'

Upvotes: 3

Views: 488

Answers (1)

Asperi
Asperi

Reputation: 258413

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 !

Upvotes: 2

Related Questions