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())
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
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"
}
}
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!
Hi everyone, can anyone tell me how can I create images for Xcode assets. Because now I want to create my own image not using the readymade.
Thank you!
Hi everyone, can anyone explain me the difference between SwiftUI and UIKit?
Thank you.
Hi everyone,
I want to use SceneKit in Swift Playgrounds, or import the Xcode project with SceneKit into Swift Playgrounds. Is it possible?
Hello everyone,
I decide to send a feedback in the Feedback app about the software beta version. But I have a question about it, when I post my feedback only Apple team can see it or it's visible to anyone?
Thanks in advance.
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.
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())
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.
Hello there!
Does anyone know how to apply Apple's default fonts to text in SwiftUI?
Hello there!
I would like to set an image as the background of my project in SwiftUI, but I have no idea how it is done.
Could anyone help me to figure out this?
I am using Swift Playgrounds and SwiftUI framework.
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.
Hey there! I have a Circle, and I would like to create many on this circle and display them in random position on the screen. Is it possible?
Thanks in advance.
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.