Now I have defined it but despite it gives me the same errors
Code:
import SwiftUI
struct ContentView: View {
let viewModel: EmojiMemoryGame
var body: some View {
VStack {
LazyVGrid(columns: [GridItem(), GridItem(), GridItem()]) {
ForEach(viewModel.cards) { card in
CardView(card: card).aspectRatio(aspectRatio, contentMode: .fit) //Cannot convert value of type '(CGFloat?, ContentMode) -> some View' to expected argument type 'CGSize'
}
}
.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
}
}
Post
Replies
Boosts
Views
Activity
@Claude31 can you reply me, please?
Try Option + Shift + K
It says me "Cannot find 'CardView22' in scope", maybe because we haven't defined the CardView22.
This is EmojiMemoryGame:
import SwiftUI
class EmojiMemoryGame {
static let emojis = ["😀", "😍", "🤪", "😱", "🥶", "🤑", "😡", "🤠", "🥳", "🤩", "🥴", "😴", "😪", "😶🌫️", "😈", "🤯", "🤐", "🤗"]
static func createMemoryGame() -> MemoryGame<String> {
MemoryGame<String>(numberOfPairsOfCards: 4) { pairIndex in
emojis[pairIndex]
}
}
private var model: MemoryGame<String> = createMemoryGame()
var cards: Array<MemoryGame<String>.Card> {
model.cards
}
}
I have defined "game" here:
import SwiftUI
@main
struct MemorizeApp: App {
let game = EmojiMemoryGame()
var body: some Scene {
WindowGroup {
ContentView(viewModel: game)
}
}
}
I was using 15.2 iOS version, and when I woke up it shows me this:
Hey!
Can show a screenshot, because otherwise it’s a little different to understand the problem.
Hello!
I actually started with an edx course, then now I’m watching some videos on YouTube. Doing in this way my knowledge is growing. You can try with this and then go on.
If you have passion you can do anything!
Hello, I link to you this page [https://www.apple.com/careers/us/) here you can see jobs opportunities at Apple. And the coding knowledge depends on what career you decide to choose.
I've updated the playground and now it's gone. Thank you anyway!
Thank you very much!
ok thanks!
Where did you define the number of the cards?
Thanks very much, it's exactly what I want!
Can you explain me what you did in the tapped() function? Because it's a little bit confusing to understand.
Yes it is correct.
Thanks very much!
I putted .overlay(Text("Hello, world!")) before .rotation3DEffect(self.flipped1 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0))), so this is my syntax now:
RoundedRectangle(cornerRadius: 20)
.frame(width: 140, height: 170)
.foregroundColor(self.flipped1 ? .yellow : .purple)
.padding()
.overlay(Text("Hello, world!"))
.rotation3DEffect(self.flipped1 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))
.animation(.default)
.onTapGesture {
self.flipped1.toggle()
}
I want the rectangle to show the text only on one face (only when it is flipped)... Instead now he shows it on all 2 faces