Post

Replies

Boosts

Views

Activity

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
598
Jan ’22
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
Preparation for Swift Student Challenge
Helle everyone! I was preparing for this year's Swift Student Challenge, and I have some questions about it. I know that Apple every year changes something in the Challenge, but I want to be ready. As I know for participating to the challenge I have to build a playground in Swift Playgrounds. So for that in Swift Playgrounds I have to use SwiftUI kit or build it in another way? PS: if someone knows some Swift Playgrounds tutorials please suggest me here. Thank you very much!
3
0
1k
Feb ’22
Need a little help with my code
Hello everyone, Can someone tell me how to move the circle in the same position of the arrow (like to go up if I press up, down if I press down... and so right if I press right) but it doesn't go right, I can't know why. Please can someone help me to figure out this? Here's the code: import SwiftUI import PlaygroundSupport struct ContentView: View {     @State var offset: CGFloat = 0     var body: some View {         Circle()             .frame(width: 80, height: 80)             .position(x: 140, y: 140 + offset)         Spacer(minLength: 20)         Button(             action: {                 offset += 20                          }, label: {                 Image(systemName: "arrowtriangle.down.circle.fill")                     .resizable()                     .foregroundColor(.blue)                     .frame(width: 70, height: 70)                     .padding()             }         )         Button(             action: {                 offset += 20                      }, label: {                 Image(systemName: "arrowtriangle.right.circle.fill")                     .resizable()                     .foregroundColor(.blue)                     .frame(width: 70, height: 70)                     .padding()             }         )     } } PlaygroundPage.current.setLiveView(ContentView()) Thanks in advance.
2
0
477
Feb ’22
Same content in 2 cards
Hello there! I'm trying to create something in SwiftUI, but there's a problem: I can't have 2 cards with the same content, does anyone know a way to have the same emojis in 2 separate cards? Here's my code: import PlaygroundSupport import SwiftUI struct ContentView: View {     var emojis: [String] = ["🐶", "🐱", "🐱", "🦊", "🦁", "🐝", "🐼", "🐷", "🐮"]     var body: some View {         LazyVGrid(columns: [GridItem(), GridItem(), GridItem()]) {             ForEach(emojis, id: \.self, content: { emoji in                 emojiView(content: emoji)             })     } }     struct emojiView: View {         var content: String = ""         var body: some View {             ZStack {                 RoundedRectangle(cornerRadius: 20)                     .frame(width: 90, height: 120)                     .foregroundColor(.yellow)                 Text(content).font(.largeTitle)             }         }     } } PlaygroundPage.current.setLiveView(ContentView())
2
0
3.6k
Mar ’22
Expand the circle throughout the screen in SwiftUI
Hi there! I'm trying to build something in SwiftUI and I need a help on it. I want the orange circle to scale and expand, and fill the entire screen, whenI click on it. Here's my code: import SwiftUI struct ContentView: View {     var body: some View {        Circle()             .frame(width: 120, height: 120)             .foregroundColor(.orange)     } } Thank you.
1
0
1.7k
Apr ’22
Error in my code
Hi everyone! I was working on a playground in Swift Playground and I got an error. I can't understand what this error means, can anyone help me? This is my code: struct Preview: View {     @State var isPlaying = true     @State var num1 = 60     @State var num2 = 150     var body: some View {         if isPlaying == true { // ERROR: Only concrete types such as structs, enums and classes can conform to protocols // Required by static method 'buildBlock' where 'C0' = ()             num1 += 1             print("\(num1)")         }     } } Thanks.
1
0
660
Apr ’22
Xcode issue
Hello everyone! I recently updated my Mac to macOS Ventura, everything was updated as expected, but I'm having a problem with Xcode, I also updated Xcode, but when I clicked on it for opening it, a message appeared which says that "In order to use Xcode, you need to update to the latest version" (despite having already updated it), so, when I go on App Store for updating it again, it already says me to open, and there isn't the Update option. I'm troubling with this problem... please if anyone knows how to fix it, help me. Thank you.
4
0
3.2k
Jun ’22