Hello everyone!
I messed up the code from the flag project too much, so I created a new application from scratch.
What do I have to do to make it work? When my code looks like this: "@State private var playerChoose = "" "
ForEach(0..<3) { number in
Button {
playerChoose == emoji[number] // RESULT OF OPERATOR '==' IS UNUSED
If I change "@State private var playerChoose = Int()" -> I get this error: Binary operator '==' cannot be applied to operands of type 'Int' and 'String'
So here is my code.
import SwiftUI
struct EmojiView: View {
@State private var emoji = ["🍏", "🍎", "🍐", "🍊", "🍋"]
@State private var random = Int.random(in: 0...2)
@State private var playerChoose = ""
@State private var spinArround = 0.0
@State private var opacity = 1.0
var body: some View {
VStack {
Text("ForEachLoop.V3")
.font(.title2)
.fontWeight(.medium)
Divider()
HStack {
ForEach(0..<3) { number in
Button {
playerChoose == emoji[number] // RESULT OF OPERATOR '==' IS UNUSED
opacity -= 0.75
spinArround += 360
} label: {
playerChoose == emoji[number] ?
Text(emoji[number])
.opacity(1)
.rotation3DEffect(.degrees(spinArround), axis: (x: 0, y: 1, z: 0))
:
Text(emoji[number])
.opacity(opacity)
.rotation3DEffect(.degrees(0), axis: (x: 0, y: 1, z: 0))
}
}