Swift Playgrounds

RSS for tag

Learn and explore coding in Swift through interactive learning experiences on the Swift Playgrounds app for iPadOS and macOS.

Swift Playgrounds Documentation

Post

Replies

Boosts

Views

Activity

Learn to code 3 missing
Hi Folks! Just started again with playgrounds, and had my "Learn to code 1-2-3" Apps on old versions. Updated 1 and 2 to 5.8, and just found that Learn to code 3 was still on old version (3.1), so decided to delete it. I was hoping that normally I'll just find it where the others are for download (Learn to code & Build Apps), but it is not there.. it is not anywhere, cannot find it, and couldn't find a way to download from anywhere else. Any ideas? Maybe for Learn to code 3 there is no Swift 5.8 yet? Thanks!
1
0
132
1w
Swift Student Challenge requires Swift Playground (.swiftpm), minimum OS setting not available.
When making a new Swift Playground via Xcode > New > Project > iOS > App Playground, as a .swiftpm package, the settings are very limited, including setting the minimum OS version. This is incredibly irritating because I can't keep make @available blocks because that would double the size of my code, and I can't use SwiftData (for example) because my app needs to also support iOS 16. Is there a way to set the minimum OS or some other upload type accepted for Apple so that I can change this simple setting? Thank you
2
0
206
2w
Seriously? I can't deploy my demo to iPad cus swift 6?
Okay everyone who click into or just pass by this post ,to cut a farrrirly long story short ,here is the thing... I was devloping my app in the playground on my Mac , which was building for the iPad, In the early time of real machine commissioning(through the Xcode ),everything is okay everything is okay.. "well,mabe it's time to deploy my app to the playground in ipad"! Then,to top it all off🤣,then playground tell me (In case that you can't understand chinese and creat ambiguity ) emm that's too tight...,so I can only got back to the Xcode changing my language version to swift 5 then..... Noting change .... and I think err.. in order to properly deploy app to iPad ,I had to rework my code with swift 5! So, I almost fell on my knees ,can somebody who in charge of the playground ,can somebody who in charge of the playground ,just ,just! shove swift 6 in the playground (as long as it make my code run anyway), otherwise there's no way to debug it! please please plase!
1
2
259
2w
LLDB RPC Server Crash Playground File XCode 16.0
When running the code below in a playground file, it crashes with an LLDB RPC Server crash. The crash log is attached. If I put the code into a project, it runs fine. lldb-rpc-server-2024-10-04-110747.txt import Foundation @objc protocol Speaker { func speak() @objc optional func tellJoke() } class Deb: Speaker { func speak() { print("Hello, I'm Deb!") } func tellJoke() { print("What did Sushi A say to Sushi B?") } } class Bryan: Speaker { func speak() { print("Yo, I'm Bryan!") } func tellJoke() { print("What is the object oriented way to become wealthy?") } func writeTutorial() { print("I'm on it!") } } class Animal {} class Dog: Animal, Speaker { func speak() { print("Woof!") } } var speaker: Speaker = Bryan() if speaker is Bryan { print("Hi, I'm a Bryan") } speaker.speak() //speaker.writeTutorial() //won't compile (speaker as! Bryan).writeTutorial() speaker = Deb() speaker.speak() speaker.tellJoke?() speaker = Dog() speaker.tellJoke?() //return nil protocol MtgSimulatorDelegate { func mtgSimulatorDidStart(sim: MtgSimulator, a: Speaker, b: Speaker) func mtgSimulatorDidEnd(sim: MtgSimulator, a: Speaker, b: Speaker) } class LoggingMtgSimulator: MtgSimulatorDelegate { func mtgSimulatorDidStart(sim: MtgSimulator, a: any Speaker, b: any Speaker) { print("Meeting started") } func mtgSimulatorDidEnd(sim: MtgSimulator, a: any Speaker, b: any Speaker) { print("Meeting ended") } } class MtgSimulator: MtgSimulatorDelegate { func mtgSimulatorDidStart(sim: MtgSimulator, a: any Speaker, b: any Speaker) { print("the meeting started") } func mtgSimulatorDidEnd(sim: MtgSimulator, a: any Speaker, b: any Speaker) { print("the meeting ended") } let a: Speaker let b: Speaker var delegate1: MtgSimulatorDelegate? var delegate2: MtgSimulatorDelegate? init(a: Speaker, b: Speaker) { self.a = a self.b = b delegate1 = self } func simulate() { print("Off to meeting....") delegate1?.mtgSimulatorDidStart(sim: self, a: a, b: b) delegate2?.mtgSimulatorDidStart(sim: self, a: a, b: b) a.speak() b.speak() print("Leaving meeting...") delegate1?.mtgSimulatorDidEnd(sim: self, a: a, b: b) delegate2?.mtgSimulatorDidEnd(sim: self, a: a, b: b) a.tellJoke?() b.tellJoke?() } }//MtgSimulator let sim = MtgSimulator(a: Deb(), b: Bryan()) sim.delegate2 = LoggingMtgSimulator() sim.simulate()
2
0
232
Oct ’24
Playgrounds issue: Has to reload the puzzle every time we test code
Hi! I have a remote student who's learning to code in Swift using Playgrounds - Learn to Code 2. It's frustrating to try to test his code when we think he as part of a solution to a puzzle because he can't run his code twice in the same puzzle without resetting the puzzle - when he tries, the page gives an error, and he has to reload the whole puzzle, which erases his code. As a workaround, he's been copying his code and reloading the puzzle whenever he wants to test out a partial solution. Is there an easier way to do this?
0
0
205
Sep ’24
Swift Playgrounds BSActionErrorDomain error 1
I am writing an app in Swift Playgrounds 4.5.1 on an iPad 8th generation running iPad OS 17.5.1. When I click the run button I get the error “MyGame Crashed. Update failed. The operation couldn't be completed. (BSActionErrorDomain error 1.) MyGame may have crashed.” It was working up until a few days ago but now it can’t even show the preview. I haven’t updated the app or software since and I can run other app playgrounds. I have multiple nested views with multiple lists of buttons using ForEach statements and I am sharing variables across views using ObservableObject using code like this: class UserProgress: ObservableObject { @Published var score = 0 } struct InnerView: View { @ObservedObject var progress: UserProgress var body: some View { Button("Increase Score") { progress.score += 1 } } } struct ContentView: View { @StateObject var progress = UserProgress() var body: some View { VStack { Text("Your score is \(progress.score)") InnerView(progress: progress) } } }
2
2
394
Jul ’24
How to access this REPL like tool used in a WWDC presentation?
I was watching this presentation about swift. A Swift Tour: Explore Swift’s features and design At timestamp 1:59, the presenter is using what looks sort of like swift playgrounds, however with a feature on the right hand side panel that is sort of like a REPL, and shows the value of an expression. How can I enable this feature? I am on the latest verison of Swift Playgrounds on macOS, and I cannot seem to find it.
1
0
529
Jun ’24
Playgrounds
I've noticed Playgrounds crashing a lot lately, both on iPad and Mac. I have many Macs, Intel & M1, and 2 iPads, 7th Gen and 10.5" Pro. It's noticeably sluggish at the best of times progressively getting worse the last few updates, but worse than that it is hard crashing, losing data in the process. Anyone else seeing this? Not the end of the world, I'm a dev and use Xcode for anything substantial but I like to use Playgrounds on the iPad sometimes when I want to pop a quick idea down. I also plan to start creating playgrounds to help kids get into programming, so hoping this useful app isn't being neglected.
2
0
705
Apr ’24