Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using index from ForEach in other array

Tags:

swift

swiftui

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'

like image 997
Tema Sysoev Avatar asked Jul 03 '26 01:07

Tema Sysoev


1 Answers

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 !
like image 132
Asperi Avatar answered Jul 05 '26 14:07

Asperi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!