Playground Support

RSS for tag

Share playground data, manage live views, and control the execution of a playground in Swift Playgrounds using Playground Support.

Posts under Playground Support tag

18 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Swift Playgrounds 4.1 keeps crashing when rerunning code
Try to learn some Swift coding but Playgrounds keeps crashing. I run Playgrounds 4.1 on latest Monterey 12.7.5, from a MacBook Air dated back 2017. Part of the error log says: Thread 9 Crashed:: Dispatch queue: com.apple.UIKit._UIViewServiceInterfaceConnectionRequest com.apple.PlaygroundsMac.ExecutionExtension The error can be reproduced by re-running the code; Everything goes well when the code was run at first time, but is doomed to fail at second run. Any help?
0
0
151
1w
Swift Playground: second episode uses unreferenced command
I am using Swift Playground to teach "coding" to my nephew. One of the strict requirements I am trying to explain him is: when you are required to solve a problem, you need to use only the instructions/harward/etc you have available. In the first episode of "Get started with code" -> "Commands" -> "Issuing commands", you are presented with two commands moveForward() and collectGem(). In the second episode "Toggle a Switch" you are introduced to a new command "toggleSwitch()". Up to this point, the learner was introduced to three commands: moveForward(), collectGem(), toggleSwitch(). However, in order to solve the puzzle in the second episode, you need also to use another command: turnLeft(), that has not been referenced. It is clear that looking for unknown commands is part of learning to code, but this occurs too early in the playground. Please consider also that some non-English young learners have no idea on how to write "turn left", so they cannot even type the first letters and hope in the auto-completion of the commands. This has not been well thought by the designers of the playground.
1
0
344
Jan ’24
Swift Playgrounds lessons not showing Swift 5.9
Hey folks! I remember some weeks/months ago to get some lessons with updated Swift 5.9, I'm just not sure if this happened while I was using Swift Playgrounds beta from TestFlight. Anyways, I went back to study using Swift Playgrounds and all the lessons are using Swift 5.8 here. I don't know what happened or how can I have the lessons updated again. Anyone else noticed this issue? Any tip on how to solve it?
7
0
701
Jan ’24
Playground issue
Hi, I'm just starting out and I'm trying to learn Swift with various tools including the Playground and I'm doing the "continue with the apps" exercises. I'm stuck at the point where I need to add the Colorpicker to change the color. The code seems right but the app won't let me move forward. struct CreatureDetail: View { /#-code-walkthrough(creatureDetail.intro)/ /#-code-walkthrough(creatureDetail.creatureConstant)/ let creature : Creature /#-code-walkthrough(creatureDetail.creatureConstant)/ //#-learning-code-snippet(addStateVarIsScaled) /*#-code-walkthrough(creatureDetail.stateVars)*/ @State var color = Color.white @State var shadowRadius : CGFloat = 0.5 @State var angle = Angle(degrees: 0) /*#-code-walkthrough(creatureDetail.stateVars)*/ var body: some View { VStack { Text(creature.emoji) .resizableFont() .colorMultiply(color) .shadow(color: color, radius: shadowRadius * 40) .rotation3DEffect(angle, axis: (x: 0.0, y: 1.0, z: 0.0)) ColorPicker("Choose a Color", selection: $color) .padding(.horizontal) } } }
2
0
502
Nov ’23
Xcode Playground "Hello, World!" Error
I've seen a few post about this issue Apple continuously has had for years now. I have tried all the solutions that I have seen, but the error still persists. I have zero to little knowledge on Swift/Xcode, coding in general, and I have no idea where to look for these issues. I believe I am using Xcode 15 on macOS Sonoma V14.0. This the error I keep receiving: error: error while processing module import: error: /var/folders/3v/dmv573gn64b364sgv041tw7c0000gn/T/playground24-a1e85e..swift:3:25: error: expected ',' in #sourceLocation directive #sourceLocation(file: ""Hello, World!".playground", line: 1) I just want to learn but this error is really discouraging lol help!
2
0
664
Oct ’23
@Observable not working in Xcode playgrounds
Creating an Observable class in an Xcode playground seems to cause an error. This stops me from being able to run the playground. As a demo, try creating a playground page and add: import Foundation import Observation // Doesn't seem to make a difference whether it's added or not. @Observable public class NewViewModel: Observable { var value: Int = 1 func increment() { value += 1 } } Tapping the run button logs the following error (and then it builds successfully, buy fails silently): error: Untitled Page.xcplaygroundpage:7:9: error: expansion of macro 'ObservationTracked()' did not produce a non-observing accessor var value: Int = 1 ^ Putting the cursor on @Observable and then selecting Editor > Expand Macro shows that value has been annotated with @ObservationTracked and I if I re-run the playground I can even see the @ObservationTracked generated code. Macros: import Foundation import Observation // Doesn't seem to make a difference whether it's added or not. @Observable public class NewViewModel: Observable { @ObservationTracked // original-source-range: /Users/gabriel.banfalvi/work/forums_observation/ObservationFramework.playground/Pages/Untitled Page.xcplaygroundpage:7:5-7:5 var value: Int = 1 { @storageRestrictions(initializes: _value) init(initialValue) { _value = initialValue } get { access(keyPath: \.value) return _value } set { withMutation(keyPath: \.value) { _value = newValue } } } // original-source-range: /Users/gabriel.banfalvi/work/forums_observation/ObservationFramework.playground/Pages/Untitled Page.xcplaygroundpage:7:20-7:23 func increment() { value += 1 } @ObservationIgnored private let _$observationRegistrar = Observation.ObservationRegistrar() internal nonisolated func access<Member>( keyPath: KeyPath<NewViewModel, Member> ) { _$observationRegistrar.access(self, keyPath: keyPath) } internal nonisolated func withMutation<Member, MutationResult>( keyPath: KeyPath<NewViewModel, Member>, _ mutation: () throws -> MutationResult ) rethrows -> MutationResult { try _$observationRegistrar.withMutation(of: self, keyPath: keyPath, mutation) } @ObservationIgnored private var _value: Int = 1 // original-source-range: /Users/gabriel.banfalvi/work/forums_observation/ObservationFramework.playground/Pages/Untitled Page.xcplaygroundpage:12:1-12:1 } I can't seem to be able to expand the @ObservationIgnored macros, which may or may not be related to the issue. I can't expand them in a regular Xcode app, but it doesn't lead to any problems there. Im running an iOS playground. I get this in Xcodes 15 beta 6 and 5. I get a different error in earlier versions.
1
0
877
Aug ’23
Swift Playgrounds: Unable to Resolve Package ‘Graphics’ and ‘unzip’ Executable Not Found Error
When I import a package in Swift Playgrounds on my iPad, I receive the following error: This package interactions with libgit2, and it don’t have any release in the origin repository, so I find a existing fork which have release. Playgrounds version: 4.3.1(1727.53) Is it means that I install a software that supports unzip on iPad?
0
0
599
Aug ’23
Learn to Code 2 > Variables > Three Gems, Four Switches
My while loop continues execution after reaching gemsCollected = 3 if I use OR logical operator (||) and stops execution if I use AND logical operator (&&). IMHO it should be the other way around, right? var gemsCollected = 0 var switchesToggled = 0 while gemsCollected < 3 || switchesToggled < 4 { moveForward() if gemsCollected < 3 && isOnGem { collectGem() gemsCollected = gemsCollected + 1 } else if switchesToggled < 4 && isOnClosedSwitch { toggleSwitch() switchesToggled = switchesToggled + 1 } else if isBlocked && !isBlockedRight { turnRight() } else if isBlocked && !isBlockedLeft { turnLeft() } }
1
0
894
Jul ’23
You don’t have permission to save the file “Laying Out Views.swiftpm” in the folder “Playgrounds”.
I randomly have errors with any playground. Is this just a random timeout with iCloud? I checked perms and my account has read & write to the playground and the folder it's (Playgrounds in iCloud Drive). I've never opened a playground and found anything missing, so it must be saving. I was not on VPN with this most recent error (though sometimes I am). I'm on an M1 Pro Mac.
0
0
769
Jun ’23