Swift Playground

RSS for tag

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

Posts under Swift Playground tag

86 Posts

Post

Replies

Boosts

Views

Activity

Reoccurring data access prompt issue with Swift Playgrounds 4.6.4 on macOS 26.1
Hello, I am having a recurring issue using Swift Playgrounds version 4.6.4 on macOS 26.1. Upon opening a file and every other time I start typing in the code section I get a prompt, the image below, two or three times. It doesn't matter if I accept or decline all or some of the prompts, as soon as I start typing on another line I get prompted another two or three times for permission. It appears to me that prompt generates every time the preview pane tries to update. Declining the prompt breaks the preview but accepting the prompt only gets you through a single line of code before it appears again. I believe this issue started after I updated to macOS26.1 as I had not encountered it before. I've also opened other files with Swift Playgrounds and encounter the same problem. It could also be unrelated to the update and could be an issue with some permission setting somewhere, however, I have been unable to find what or where it could be. Is anyone else experiencing this? Thank you for your time :)
6
3
138
14h
Swift Playground preview issues
I am a high school teacher from China, currently teaching programming courses at my school. Several issues are preventing the course from being completed on schedule. As shown in the image, there are two problems: The preview issue has existed since updating to the latest software and system version; I don't know how to resolve it. After renaming a Swift file, this window keeps popping up, even after closing it. This problem didn't exist last year. How can I fix this? Thank you for your reply! 我是一名来自中国的高中教师,目前在学校开设编程课程,目前有几个问题导致课程无法如期完成。如图所示,存在两个问题: 一、自从更新了最新版本的软件和系统后,预览问题就存在,不知该如何处理 二、swift文件重命名后,一直跳出来这个窗口,关掉以后还是跳出来 去年的时候还没有存在这样的问题,请问我该如何处理,感谢您的回复!
2
0
52
15h
Help - Can't switch off security warning
Hi, I'm using Swift Playground version 4.6.4 (1997.50) on macOS Tahoe 26.1 and when I create new apps, I get a security warning message every time I try to add a new line of code or switch between ContentView and MyApp source files 🤬 The message is "My app.app would like to access data from other apps" I've checked my Mac's Privacy & Security settings to ensure Playground has full disk access. Clicking the "Allow" button does not resolve the issue, it keeps happening each time I do anything - its makes Playground unusable 😞 Does anyone know how to stop these messages ? Is this a bug ?
4
1
182
1d
“Keep Going with Apps” Tutorial section will not complete.
Hello All, I am currently working through ”Keep going with Apps” in Swift Playground. The section in the tutorial “Add a DancingCreature view” will not complete. I have tried to type it is as written in the tutorial and even used the copy and paste button provided. I have restarted the app and my IPad with no success. I have attached a screen shot of the tutorial prompt. Here is the code block: import SwiftUI import Guide struct DancingCreatures: View { //#-learning-code-snippet(varDeclaration) @EnvironmentObject var data : CreatureZoo var body: some View { SPCAssessableGroup(view: self) { VStack { ZStack { /*#-code-walkthrough(dance.forEach)*/ ForEach(data.creatures) { creature in /*#-code-walkthrough(dance.forEach)*/ /*#-code-walkthrough(dance.textView)*/ Text(creature.emoji) .resizableFont() .offset(creature.offset) .rotationEffect(creature.rotation) /*#-code-walkthrough(dance.textView)*/ } } ZStack { /*#-code-walkthrough(dance.forEach)*/ ForEach(data.creatures) { creature in /*#-code-walkthrough(dance.forEach)*/ /*#-code-walkthrough(dance.textView)*/ Text(creature.emoji) .resizableFont() .offset(creature.offset) .rotationEffect(creature.rotation) /*#-code-walkthrough(dance.textView)*/ //#-learning-code-snippet(exp1) //#-learning-code-snippet(animationSolution) //#-learning-code-snippet(exp3) } } /*#-code-walkthrough(dance.onTap)*/ .onTapGesture { data.randomizeOffsets() } /*#-code-walkthrough(dance.onTap)*/ /*#-code-walkthrough(dance.onTap)*/ .onTapGesture { data.randomizeOffsets() } /*#-code-walkthrough(dance.onTap)*/ } } } } struct DancingCreatures_Previews: PreviewProvider { static var previews: some View { DancingCreatures().environmentObject(CreatureZoo()) } } Device information: IPad Pro (11 inch, 2nd gen) iPad OS Version: 26.0.1 Playground Version: 4.6.4 Anyone else come across this? Thank you in advance.
1
0
57
2w
Swift Playgrounds Incompatibility with Xcode 16 Files and Swift Versions
I'm facing an issue with Swift Playgrounds and files created in Xcode 16. It seems that Swift Playgrounds does not support Swift 6, but even when I create files specifically with Swift 5, Swift Playgrounds still reports that the files are unsupported. This creates a significant problem because macOS Sequoia does not allow me to revert to Xcode 15, which might have offered better compatibility. As it stands, I can't find a solution to work seamlessly between Xcode and Swift Playgrounds. Has anyone else encountered this issue? Are there any workarounds or updates planned to address this compatibility gap? Any advice would be greatly appreciated!
5
1
889
3w
IPad OS 16.1, Playgrounds and input fields
I have installed the latest beta on my iPad , iPadOS 16.1 (20B5050f) On running in app in Playgrounds that has a TextField, external keyboard input do not seem to be working. Tapping on the Text field inserts the cursor but no text can be entered on my external keyboard. (TextEditor field also do not work) Tested with both a Smart Keyboard and a Magic Keyboard. The keyboard works to enter the code in playgrounds, so it is not a keyboard connection issue. Disconnecting the keyboard, the onscreen keyboard is displayed and works correctly. Is this a Playgrounds issue or an iPadOS 16.1 issue or a compatibility issue with Playgrounds & iPadOS 16.1 ? import SwiftUI struct ContentView: View {     @State var field: String = "Test input"          var body: some View {         VStack {             Image(systemName: "globe")                 .imageScale(.large)                 .foregroundColor(.accentColor)             Text("Hello, world!")             TextField("", text: $field)                 .frame(height: 100)         }     } }
3
0
1.6k
Sep ’25
Core Data stack in #Playground
I'm using the #Playground macro in Xcode 26.0, running on macOS 26.0. I can get the basics working, but I don't understand how it hooks into the rest of the app, like the App Delete or the Core Data stack. Do we have to create a new Core Data stack, like for SwiftUI Previews, or can it hook into the stack from the main app (if so, how)?
1
0
133
Jul ’25
Does Swift Playground Support Custom Code Snippets Like Xcode?
While demonstrating Swift Playground to my students, I noticed that, unlike Xcode, it doesn’t seem possible to predefine or insert custom code snippets. In Xcode, we can easily create and reuse our own code snippets to improve teaching and development efficiency, but I couldn’t find a similar feature in Swift Playground. Is there currently a way to predefine or insert custom code snippets in Swift Playground? Are there any recommended workarounds, or plans to support this feature in the future? Any suggestions or insights would be greatly appreciated.
1
0
65
Jul ’25
Swift Playground crashes
I'm trying to use the new #Playground feature in Xcode, but it keeps crashing in the canvas. I am testing on Xcode 26.0 beta 4, on both macOS 15 and macOS26 beta 4. How do I figure out what's going on? I also have a few SwiftUI previews in my project, which also crashes if I try to preview them. They're not in any active tab right now in Xcode. But the #Playground feature still doesn't work. I also don't get a crash when working on a #Playground in a different project. I've tried cleaning out Derived Data and restarting the Mac / Xcode, all with no avail. How do I track down what's causing this? Do previews and playground run on the same engine? System Integrity Protection: enabled Triggered by Thread: 0 Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Termination Reason: Namespace OBJC, Code 1, Thread 0 Crashed: 0 libsystem_kernel.dylib 0x100634ad0 __abort_with_payload + 8 1 libsystem_kernel.dylib 0x100659dc0 abort_with_payload_wrapper_internal + 100 2 libsystem_kernel.dylib 0x100659d5c abort_with_reason + 28 3 libobjc.A.dylib 0x18009bd08 _objc_fatalv(unsigned long long, unsigned long long, char const*, char*) + 112 4 libobjc.A.dylib 0x18009bc98 _objc_fatal(char const*, ...) + 28 5 libobjc.A.dylib 0x18008be14 lookUpImpOrForward + 580 6 libobjc.A.dylib 0x180072f00 _objc_msgSend_uncached + 64 7 ??? 0x340a44048 ??? 8 CJournal 0x1001c54c4 __debug_blank_executor_run_user_entry_point + 152 9 PreviewsInjection 0x241623bf4 0x2415ff000 + 150516 10 PreviewsInjection 0x24162481c 0x2415ff000 + 153628 11 PreviewsInjection 0x241624740 __previews_injection_run_user_entrypoint + 12 12 XOJITExecutor 0x25543ad48 __xojit_executor_run_program_wrapper + 1460 13 XOJITExecutor 0x25543725c 0x255435000 + 8796 14 PreviewsInjection 0x24162468c 0x2415ff000 + 153228 15 CJournal 0x1001c4c7c __debug_blank_executor_main + 996 16 ??? 0x1003e13d0 ??? 17 dyld 0x100218924 start + 6400
2
1
161
Jul ’25
Liquid Glass Error
Hello everyone. I'm getting an error in my code and I don't know why. Can someone explain it to me? import SwiftUI struct ContentView: View{ var body: some View{ VStack { Button {} label: { Text("Click Me") } .buttonStyle(.glass) .frame(width: 200, height: 200) } } } The error is as follows: Reference to member 'glass' cannot be resolved without a contextual type Thanks for your help
1
0
246
Jul ’25
Main actor-isolated property can not be referenced
Hello I'm getting this error in my code and I don't know why. Can somebody explain this or point me at a help article. import UIKit var greeting = "Hello, playground" let imageView = UIImageView() imageView.image = UIImage(named: "image") Utils.getImageSize(view: imageView) class Utils { static func getImageSize(view imageView: UIImageView) { let image = imageView.image print("Image size = \(image?.size ?? CGSize.zero)") } } The error is as follows: Cheers Murray
4
0
186
Jul ’25
Beginner Question - Local SPM Folder Structure
Hi there, I am working on an iOS mobile app, with a MVVM architecture and created an SPM folders for my DesignSystem, CoreKit, UnityBridge, and VoicePipeline. I added the packages locally, and dragged them into the project. Is working this way recommended? Or not? Should all the SPM folders I listed above be used this way, or should only some? New to this, unsure what is best. I do plan on sharing my code with other devs to work on. I thought this made sense, but if i did it the other way I was unsure how I would share the packages what is a best practice. Thanks so much!
1
0
99
Jul ’25
Issue with #Playground and Foundation Model
Hi all, I’m encountering an issue when trying to run Apple Foundation Models in a blank project targeting iOS 26. Below are the details: Xcode: Latest version with iOS 26 SDK macOS: macOS 26 Tahoe (installed on main disk) Mac: 16” MacBook Pro with M2 Pro chip Apple Intelligence: Available and functional on this machine Problem: I created a new blank iOS project, set the deployment target to iOS 26, and ran the following minimal code using Foundation Models. However, I get no response at all in the output - not even an error. The app runs, but the model does not produce any output. #Playground { let session = LanguageModelSession() let response = try await session.respond(to: "Tell me a story") } Then, I tried to catch an error with this code: #Playground { let session = LanguageModelSession() do { let response = try await session.respond(to: "Tell me a story") print(response) } catch { print("Failed to get response:", error) } print("This line, never gets executed") } And got these results: I’ve done further testing and discovered something important: I tried running the Code Along sample project, and there the #Playground macro worked without issues. The only significant difference I noticed was the Canvas run destination: In my original project, I was using iPhone 16 Pro (iOS 26) as the run target in Canvas. Apple Intelligence was enabled on the simulator, but no response was returned when executing the prompt. In the sample project, the Canvas was running on My Mac. I attempted to match that setup, but at first, my destination was My Mac (Designed for iPad), which still didn’t work. The macro finally executed properly once I switched to My Mac (AppKit). So the question is ... it seems that for now, Foundation Models and the #Playground macro only run correctly when the canvas or destination is set to “My Mac (AppKit)”?
7
0
472
Jul ’25
Swift Playgrounds 4.6 removes support for libraries?
I had several library projects that were working in Swift Playgrounds < 4.6 but I get several duplicate compilation errors and previews will not build in Swift Playgrounds > 4.6. Does anyone know how to fix this issue? Example project: This project builds and runs fine under Swift Playgrounds 4.5.1 however it will not run complaining multiple commands produce generated output files under Swift Playgrounds 4.6.1, 4.6.2, and 4.6.3. https://github.com/kudit/Compatibility Download this repository and add the extension ".swiftpm" to the folder and double click to open in Swift Playgrounds. If running on earlier Swift Playgrounds you can see there are no errors and previews work great (on both macOS and iPadOS versions of Swift Playgrounds 4.5.x). However, on Swift Playgrounds 4.6.x, previews will not display. Are embedded libraries not support anymore? This would be very disappointing. I posted this as a Feedback weeks ago with no response: FB16509699
4
0
392
Jun ’25
Checking the contents of a TextField variable method not working
Hoping someone can help me with this… The error is… Generic parameter ‘/‘ cannot be inferred. .multilineTextAlignment(.center) .onAppear(perform: { var checkFirstCardLatitude = cards.firstCardLatitude let charArray = Array(checkFirstCardLatitude) let allowed: [Character] = ["-", ".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] for char in charArray { if char != allowed { cards.firstCardLatitude = "000.000000" // Reset Text Field } } })
26
0
374
May ’25
LLDB RPC server crash in Xcode 16.3
Created a new project in Xcode 16.3. While adding breakpoints app is crashing every time in Xcode and playground both. Tried with swift 5 and swift 6 getting same error. Crash reason : Couldn't find the Objective-C runtime library in loaded images. Message from debugger: The LLDB RPC server has crashed. You may need to manually terminate your process lldb-rpc-server-2025-04-14-092736.txt
4
6
360
May ’25