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.9k
Aug ’22
Print something on the screen
Hello there! I would like to print the number 5 on the screen when I click the Button, but I don't know how I can do it... if I write print("5") it prints me the number 5 in the debug area of Xcode. Can someone help me to figure out this? Here's may code Thanks a lot Button {         } label: {             ZStack {                 Circle()                     .frame(width: 90, height: 90)                     .foregroundColor(Color(.systemBlue))                     .opacity(0.5)                                     Text("5")                     .font(.largeTitle)                     .bold()                     .foregroundColor(.black)             }             .frame(width: 90, height: 90)         }
9
0
1.1k
Jan ’22
Result of 'Text' initializer is unused
Hi, in this code it gives me the warning "Result of 'Text' initializer is unused" near Text("(Number)"). Does someone know what exactly mean this warning and how can I fix it? Thanks in advance struct NewView: View {     var body: some View {         Button {             tapped()         } label: {             Text("hello")         }     } }               func tapped() {     Text("\(Number)") } struct NewView_Previews: PreviewProvider {     static var previews: some View {         NewView()     } }
6
0
5.2k
Dec ’21
Change the position of a shape
Hi everyone, do you know the command to change the position of a shape. I want to change the position of a Rectangle and draw it to the right, this was the code that I tried: But it shows me that blue frame around and when I click on it (since it is a button) I can’t click outside that frame. Please help me… Thank you in advance ;)
5
0
2.3k
Dec ’21
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
1.1k
Jan ’22
Create a button
Hello everyone. I would like to create a button in SwiftUI, which initially will display some text and with the click of the user will transform to a number (like initially the button displays "click me to add a number" and when I click on it'll immediately displays number "1" ). Can anyone help me with how to do this? Thanks
4
0
606
Dec ’21
Text background color
Hi guys do you know how to change the text background color in SwiftUI? .foregroundColor() changes the text color .background(Color) changes all the background's color So which is the command that changes only the text background color? Thanks
4
0
5.7k
Dec ’21
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
704
Jan ’22