Post

Replies

Boosts

Views

Activity

How to fix these errors?
Hello there! I want to create a cards game, and I'm creating it following the Stanford University's tutorial. I followed the video step by step but there is a warning that In the video doesn't appear. Can someone help me to fix it? Here's the link of the video: [https://www.youtube.com/watch?v=oWZOFSYS5GE&t=671s) This is my 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) // here's the first error which says "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) //here's the second error which says "Cannot find 'game' in scope"     } }
14
0
1.6k
Jan ’22
iOS 15.2.1
Hello everyone! I have updated my iPhone to iOS 15.2.1 and before this update my phone after the good the sleep mode turns off, it appears a screen with written on it “Good Morning” and the weather. But since I have updated my device to iOS 15.2.1 it isn’t showing me this screen. Is it a feature that Apple has deleted or is this a bug? Thank you.
3
0
1.2k
Jan ’22
Scroll automatically
Hi there! I'm trying to create an app which scrolls automatically when my mouse goes to the top of the screen or to the bottom. For example the mouse goes towards the top, it has to scroll to the top and vice versa. So if it possible help me please. Thanks very much! I leave you my code: import SwiftUI import PlaygroundSupport struct ContentView: View {     var body: some View{         HStack {             CardView()             CardView()             CardView()             CardView()         }         .padding()         .foregroundColor(Color(.systemRed))     } } struct CardView: View {     @State var isFaceUp = false     var body: some View {         ZStack {             let shape = RoundedRectangle(cornerRadius: 20)             if isFaceUp {                 shape.fill().foregroundColor(.white)                 shape.stroke(lineWidth: 3)                 Text("😀").font(.system(size: 80))             } else {                 shape.fill()             }         }          .onTapGesture(perform: {             isFaceUp = !isFaceUp         })     } } PlaygroundPage.current.setLiveView(ContentView())
0
0
700
Jan ’22
Scroll according to mouse position
Hey there, I would like to create a card game (I'm following the Stanford University's tutorial) and I want to Scroll the view according to the position of the mouse, like if it's to the top so I would like that it automatically rolls up, so if it's to the down, scroll automatically to the down: This is my code: import SwiftUI import PlaygroundSupport struct ContentView: View {     var body: some View{         HStack {             CardView()             CardView()             CardView()             CardView()         }         .padding()         .foregroundColor(Color(.systemRed))     } } struct CardView: View {     @State var isFaceUp = false     var body: some View {         ZStack {             let shape = RoundedRectangle(cornerRadius: 20)             if isFaceUp {                 shape.fill().foregroundColor(.white)                 shape.stroke(lineWidth: 3)                 Text("😀").font(.system(size: 80))             } else {                 shape.fill()             }         }          .onTapGesture(perform: {             isFaceUp = !isFaceUp         })     } } PlaygroundPage.current.setLiveView(ContentView())
0
0
346
Jan ’22
Scroll according to mouse position
Hey there, I would like to create a card game (I'm following the Stanford University's tutorial) and I want to Scroll the view according to the position of the mouse, like if it's to the top so I would like that it automatically rolls up, so if it's to the down, scroll automatically to the down: import SwiftUI import PlaygroundSupport struct ContentView: View {     var body: some View{         HStack {             CardView()             CardView()             CardView()             CardView()         }         .padding()         .foregroundColor(Color(.systemRed))     } } struct CardView: View {     @State var isFaceUp = false     var body: some View {         ZStack {             let shape = RoundedRectangle(cornerRadius: 20)             if isFaceUp {                 shape.fill().foregroundColor(.white)                 shape.stroke(lineWidth: 3)                 Text("😀").font(.system(size: 80))             } else {                 shape.fill()             }         }          .onTapGesture(perform: {             isFaceUp = !isFaceUp         })     } } PlaygroundPage.current.setLiveView(ContentView())
0
0
333
Jan ’22
Where to put the animation
Hello! I was trying to create a cards game following the Stanford University CS193p tutorial and I had a problem, in the tutorial they didn't add any animation and I would like to add one but I can't understand where exactly I have to write the command. Can someone help me? Thank you very much! My code: import SwiftUI import PlaygroundSupport struct ContentView: View {     var body: some View{         HStack {             CardView()             CardView()             CardView()             CardView()         }         .padding()         .foregroundColor(Color(.systemRed))     } } struct CardView: View {     @State var isFaceUp = false     var body: some View {         ZStack {             let shape = RoundedRectangle(cornerRadius: 20)             if isFaceUp {                 shape.fill().foregroundColor(.white)                 shape.stroke(lineWidth: 3)                 Text("😀").font(.system(size: 80))             } else {                 shape.fill()             }         }          .onTapGesture(perform: {             isFaceUp = !isFaceUp         })     } } PlaygroundPage.current.setLiveView(ContentView())
2
0
542
Jan ’22
Keep face up the cards if equal
Hi guys, I need a little help with my code, I was creating this playground and I want that the cards will stay face up if they are equal... I can't find tutorial and I tried different lines of code but it doesn't work. So please can anyone help me there? I'll thank you very much. struct ContentView: View {     @State var flipped1 = false      @State var flipped2 = false      var body: some View {               LazyVGrid(columns: columns) {             Group {                 RoundedRectangle(cornerRadius: 20)                     .frame(width: 140, height: 170)                     .foregroundColor(flipped1 ? Color(.systemIndigo) : .purple)                     .padding()                     .overlay(Text("😀").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped1 ? 180 : 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0))).opacity(flipped1 ? 1 : 0))                     .rotation3DEffect(flipped1 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))                     .animation(.default, value: flipped1)                     .onTapGesture {                         flipped1.toggle()                     }                                  RoundedRectangle(cornerRadius: 20)                     .frame(width: 140, height: 170)                     .foregroundColor(flipped2 ? Color(.systemIndigo) : .purple)                     .padding()                     .overlay(Text("😀").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped2 ? 180 : 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0))).opacity(flipped2 ? 1 : 0))                     .rotation3DEffect(flipped2 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))                     .animation(.default)                      .onTapGesture {                         flipped2.toggle()                     }
4
0
564
Jan ’22
Need a help with my app
Hi guys I'm trying to build a game (cards game precisely) and I need that when the user finds the same cards the game has to stop... I watched different videos on internet and tried a lot of lines of code but I can't do this. So please, can anyone help me? Thank you. I leave you my code: import SwiftUI import PlaygroundSupport let columns = [GridItem(.flexible()),                GridItem(.flexible()),                GridItem(.flexible()),                GridItem(.flexible())] struct ContentView: View {     @State var flipped1 = false      @State var flipped2 = false      @State var flipped3 = false      @State var flipped5 = false      @State var flipped6 = false      @State var flipped7 = false      @State var flipped8 = false      @State var flipped9 = false           var body: some View {         LazyVGrid(columns: columns) {             Group {                 RoundedRectangle(cornerRadius: 20)                     .frame(width: 140, height: 170)                     .foregroundColor(flipped1 ? Color(.systemIndigo) : .purple)                     .padding()                     .overlay(Text("😀").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped1 ? 180 : 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0))).opacity(flipped1 ? 1 : 0))                     .rotation3DEffect(flipped1 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))                     .animation(.default, value: flipped1)                     .onTapGesture {                         flipped1.toggle()                     }                 RoundedRectangle(cornerRadius: 20)                     .frame(width: 140, height: 170)                     .foregroundColor(flipped2 ? Color(.systemIndigo) : .purple)                     .padding()                     .overlay(Text("😜").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped2 ? 180 : 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0))).opacity(flipped2 ? 1 : 0))                     .rotation3DEffect(flipped2 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))                     .animation(.default)                      .onTapGesture {                         flipped2.toggle()                     }                                  RoundedRectangle(cornerRadius: 20)                     .frame(width: 140, height: 170)                     .foregroundColor(self.flipped3 ? Color(.systemIndigo) : .purple)                     .padding()                     .overlay(Text("😘").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped3 ? 180 : 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0))).opacity(flipped3 ? 1 : 0))                     .rotation3DEffect(self.flipped3 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))                     .animation(.default)                      .onTapGesture {                         self.flipped3.toggle()                     }                                  RoundedRectangle(cornerRadius: 20)                     .frame(width: 140, height: 170)                     .foregroundColor(self.flipped5 ?  Color(.systemIndigo) : .purple)                     .padding()                     .overlay(Text("🥶").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped5 ? 180 : 0), axis: (x: CGFloat(0), y:CGFloat(10), z: CGFloat(0))).opacity(flipped5 ? 1 : 0))                     .rotation3DEffect(self.flipped5 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))                     .animation(.default)                      .onTapGesture {                         self.flipped5.toggle()                     }                 RoundedRectangle(cornerRadius: 20)                     .frame(width: 140, height: 170)                     .foregroundColor(self.flipped6 ? Color(.systemIndigo) : .purple)                     .padding()                     .overlay(Text("😡").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped6 ? 180 : 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0))).opacity(flipped6 ? 1 : 0))                     .rotation3DEffect(self.flipped6 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))                     .animation(.default)                      .onTapGesture {                         self.flipped6.toggle()                     }                                  Group {                     RoundedRectangle(cornerRadius: 20)                         .frame(width: 140, height: 170)                         .foregroundColor(self.flipped7 ? Color(.systemIndigo) : .purple)                         .padding()                         .overlay(Text("🥶").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped7 ? 180 : 0), axis: (x: CGFloat(0), y:CGFloat(10), z: CGFloat(0))).opacity(flipped7 ? 1 : 0))                         .rotation3DEffect(self.flipped7 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))                         .animation(.default)                          .onTapGesture {                             self.flipped7.toggle()                         }                     RoundedRectangle(cornerRadius: 20)                         .frame(width: 140, height: 170)                         .foregroundColor(self.flipped8 ? Color(.systemIndigo) : .purple)                         .padding()                         .overlay(Text("😘").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped8 ? 180 : 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0))).opacity(flipped8 ? 1 : 0))                         .rotation3DEffect(self.flipped8 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))                         .animation(.default)                          .onTapGesture {                             self.flipped8.toggle()                         }                     RoundedRectangle(cornerRadius: 20)                         .frame(width: 140, height: 170)                         .foregroundColor(self.flipped9 ? Color(.systemIndigo) : .purple)                         .padding()                         .overlay(Text("😡").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped9 ? 180 : 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0))).opacity(flipped9 ? 1 : 0))                         .rotation3DEffect(self.flipped9 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))                         .animation(.default)                          .onTapGesture {                             self.flipped9.toggle()                         }                                      }             }         }     } } PlaygroundPage.current.setLiveView(ContentView())
2
0
485
Jan ’22
Add Text to an animated object
Hello guys, everything was working perfectly but I can't do a thing please help me. I was trying to put into this Rectangle some text , I've tried several lines of code but I can't put the Text INTO the rectangle. Can someone help me? Here's the code import SwiftUI import PlaygroundSupport struct ContentView: View {     @State  var flipped = false      var body: some View {                      Group {                 RoundedRectangle(cornerRadius: 20)                     .frame(width: 140, height: 170)                     .foregroundColor(self.flipped ? .red : .orange)                     .padding()                     .rotation3DEffect(self.flipped ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))                     .animation(.default)                      .onTapGesture {                         self.flipped.toggle()                                              }             }                          }     } PlaygroundPage.current.setLiveView(ContentView())
1
0
494
Jan ’22
Add Text to an animated object
Hello guys, everything was working perfectly but I can't do a thing please help me. I was trying to put into this Rectangle some text , I've tried several lines of code but I can't put the Text INTO the rectangle. Can someone help me? Here's the code import SwiftUI import PlaygroundSupport struct ContentView: View {     @State  var flipped = false      var body: some View {                      Group {                 RoundedRectangle(cornerRadius: 20)                     .frame(width: 140, height: 170)                     .foregroundColor(self.flipped ? .red : .orange)                     .padding()                     .rotation3DEffect(self.flipped ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))                     .animation(.default)                      .onTapGesture {                         self.flipped.toggle()                                              }             }                          }     } PlaygroundPage.current.setLiveView(ContentView())
5
0
897
Jan ’22
Flip animation in SwiftUI
Hello everyone, I would like to a flip animation, so that when I press on the rectangle it will flip to other side (like in a cards game) How can I do that? Thank you Here's my code: import SwiftUI import PlaygroundSupport struct ContentView: View {     var body: some View {                      Group {                 Button {                                      } label: {                     Rectangle()                         .frame(width: 140, height: 170)                         .foregroundColor(Color(.systemTeal))                         .cornerRadius(20)                 }             }     } } PlaygroundPage.current.setLiveView(ContentView())
1
0
2.6k
Jan ’22