In Swift Playground 4.6.2 the package PlaygroundSupport is no longer available to Playground apps. The following test previously permitted apps run in the Playground vs compiled in XCode to support different behavior:
#if canImport(PlaygroundSupport)
container = NSPersistentContainer(name: "myApp", managedObjectModel: Self.createModel())
#else
container = NSPersistentCloudKitContainer(name: "myApp")
#endif
Since Swift Playground 4.6.2 the PlaygroundSupport package is no longer available for app projects in Playgrounds.
Is there a different compile type test which can be used to differentiate compilation for Swift Playground apps ?
I am currently having to use a runtime workaround (below) but would prefer a compile time test is an alternative is available.
public static var inPlayground: Bool {
if Bundle.allBundles.contains(where: { ($0.bundleIdentifier ?? "").contains("swift-playgrounds") }) {
return true
} else {
return false
}
}
Playground Support
RSS for tagShare playground data, manage live views, and control the execution of a playground in Swift Playgrounds using Playground Support.
Posts under Playground Support tag
22 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Hi everyone,
I'm currently working on a Swift Playgrounds project where I need to incorporate a Metal shader file. However, when I tried to include my shader file (PincushionShader.metal), I encountered the following error:
Is it possible to use Metal shader files within Swift Playgrounds, it is really important for my swift student challenge scene? If not, are there any workarounds or recommended approaches for testing Metal shaders in a similar environment?
Any guidance or suggestions would be greatly appreciated!
I am currently preparing my submission for the Swift Student Challenge, and my app playground is quite comprehensive. Based on my estimations, it may take approximately 4 to 5.5 minutes for the reviewers to fully experience the interactive elements of my app. Every component is integral to the overall experience, and I would prefer not to remove any content, as each part not only contributes to the overall interactivity but also effectively demonstrates my abilities across different technical and creative domains.
However, I noticed the guideline on https://developer.apple.com/swift-student-challenge/eligibility stating that the interactive scene should be “experienced within three minutes.” While this does not appear to be a main requirement, my app playground significantly exceeds this timeframe.
Could you kindly clarify whether exceeding the three-minute guideline could result in my submission being rejected, or if it might negatively impact the evaluation process? I would greatly appreciate any insights you can provide.
Thank you for your time and consideration. I look forward to your response.
I'm preparing my submission for the Swift Student Challenge, and I have a couple of questions regarding the development environment.
Is it allowed to use Xcode to program my scene, or do I have to use Swift Playgrounds?
Can I use iPadOS 18 for development? I noticed that Swift Playgrounds currently only supports up to iPadOS 17.5, but I would like to use RealityView, which is only available starting from iPadOS 18.
I appreciate any clarification on this. Thanks in advance!
I use Swift Playgrounds on iPad to run an intro to programming class with high school students. I've created some custom playground books based on Apple's guides to provide some simple sandboxes to learn basic coding.
Students simply click a button on my website, which downloads my playground books so students can easily create new sandboxes.
With Swift Playgrounds 4.6.1 on both Mac and iPad, clicking the link only opens Swift Playgrounds and does not download my playground books! There used to be an "Add a Subscription URL" button, but it is no longer present on the Learn to Code page or anywhere else in the app that I can find:
Is it intentional that this functionality is removed? Playground Books still appear to work, and documentation for subscription feeds is still available.
I start another session with my students next Monday, so I need to know as soon as possible whether I need to plan to work around this myself.
Thanks,
Mark Schmidt
I see the solution is simple "just change the language in the build settings" but the build settings are not a thing in an App Playground project. It also says duplicated tasks.
Hey there-
I'm having a quite interesting bug on Swift Playgrounds.
I am trying to run my app with this following code snippet which does not compile on Swift Playgrounds, yet compiles on XCode (note: this is a Swift Playground app)
if #available(iOS 18.0, *) {
//simple function to get the indices of other items that have the same date as the "date" variable
let indices = data!.indices(where: { item in
let sameMonth = Calendar.current.component(.month, from: item.time) == Calendar.current.component(.month, from: date)
let sameYear = Calendar.current.component(.year, from: item.time) == Calendar.current.component(.year, from: date)
let sameDay = Calendar.current.component(.day, from: item.time) == Calendar.current.component(.year, from: date)
return sameDay && sameMonth && sameYear
})
However, the indices(where:) codeblock seems to stop the app from compiling (ONLY on Swift Playgrounds - it works perfectly fine on XCode).
I am getting the following error:
Cannot call value of non-function type 'Range<Array<Int>.Index>' (aka 'Range<Int>')
Please let me know if you have any insight regarding this issue.
-ColoredOwl
I keep trying to use the app but every time I try to click the module "get started with code" it crashes and produces an error log, attached.
Crash log
Hi, I have recently downloaded the app to start learning how to code in swift and so on.
On my first try I have gotten the error stating that ”.swiftpm files cannot be opened”. I have followed some forum posts. I restarted my iPad several times and redown the app several times. I tried to disable the iCloud sync but I think I deleted the iCloud directory entirely that just results in the app closing on any action taken. (such as pressing the “New App” option or choosing the quick actions to make apps).
Is there a way to fix this?
Any help is appreciate, please ask me to provide any extra needed information.
I’m curious about the situation since the Playgrounds haven’t released a new version to support the numerous new frameworks released this year at WWDC24. How are we supposed to build with these new frameworks if they haven’t even been released for Playgrounds for the Swift Student Challenge?
Hi,
First post and I am a total newbie when it comes to Ipads & Macs... And also this forum, so sorry if I post in wrong section.
My son use Ipad at school and they use Swift Playground there.
To be able to do some programming at home, I have set up Vmware with Sequoia 15.1.
I installed the app Swift Playground and try to run the playground Get Started with Code and some other education playgrounds.
If I understand correctly, it should be some landscape and a figure on the canvas... For me it is only a blue area.
I installed XCode, but could not figure out how to run the learning examples there. Tips? Is it possible to run the education playgrounds there?
I removed Swift Playgrounds and installed it again, same issue.
I also installed IOS 18.1 (?) but I am not sure it is needed.
Any suggestion of how I can get contents to show on the canvas? Except of bying an Ipad. ;)
Hi apple I have been stuck for 2 days and it still does not work
Updated to iOS 18.2 beta 1 as soon as it was released on iPhone 15 pro max. playground icon on Home Screen but been waiting all this time and no activation. Dose anyone know if there is a known fault.
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!
I am currently running MacOS 12.7.6 version and this is the last update on my machine, and swift playgrounds is not downloading in it, so I want its older version, I think I need Swift Playgrounds 4.1, so please give me a solution.
Thank you so much!
hi
im fairly new to coding.. about a month, just so u know.. 😇
I am going through the tasks in (Swift Playgrounds) and I am currently in (Learning to code 2) the chapter is (Random gems everywhere) and I tried every possible solution to complete it, but to no avail!
any suggestions, comments, or corrections or tips, would be greatly appreciated!
I will attach some screenshots for a reference of what I'm trying to accomplish..
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?
In Swift-UI Playgrounds Learn to Code 2 under the Chapter "Variables" and the exercise "Checking for Equal Values", there is no instruction to use the predefined variable numberOfSwitches in the goal instruction.
Does anyone know of any documentation for the various directives in the guidebook?
Things like @GuideBook, @Guide, @Task, @SuccessMessage, etc.
Thanks,
David
I was expecting all of the code to run in main thread, but both task and async function is working in backfround thread. Any explanations?