Yes I was responding to you. It seams that you changed something, I'm sorry.
Now I have tried to put CardView(card: card).aspectRatio(2.0, contentMode: ContentMode.fit) into my code and then put @State before aspectRatio. So this the updated code:
import SwiftUI
struct ContentView: View {
let viewModel: EmojiMemoryGame
@State var aspectRatio = 1
var body: some View {
let emojis = ["😀", "😍", "🤪", "😱", "🥶", "🤑", "😡", "🤠", "🥳", "🤩", "🥴", "😴", "😪", "😶🌫️", "😈", "🤯", "🤐", "🤗"] //WARNING: Initialization of immutable value 'emojis' was never used; consider replacing with assignment to '_' or removing it. Replace 'let emojis' with '_'
var emojiCount = 4
VStack {
LazyVGrid(columns: [GridItem(), GridItem(), GridItem()]) {
ForEach(viewModel.cards) { card in
CardView(card: card).aspectRatio(2.0, contentMode: ContentMode.fit)
}
}
.padding()
.foregroundColor(Color(.systemTeal))
Spacer()
Button {
emojiCount += 1
if emojiCount == 10 {
aspectRatio = 9/3
}
if emojiCount > 17 {
print("Card finished")
}
} label: {
Text("Add Card")
}
}
}
}
struct CardView: View {
let card: MemoryGame<String>.Card
var body: some View {
ZStack {
let shape = RoundedRectangle(cornerRadius: 20)
if card.isFaceUp {
shape.fill().foregroundColor(.white)
shape.stroke(lineWidth: 3)
Text(card.content).font(.system(size: 50))
} else {
shape.fill(.orange)
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView(viewModel: game) //Cannot find 'game' in scope
}
}
Now it gives me one Warning and an Error :(