Dare anyone try the following code in any Playground:
// Define a model that conforms to Codable
struct User: Codable {
var name: String
var age: Int
var email: String?
}
// JSON data (as a string for demonstration)
let jsonString = """
{
"name": "John Doe",
"age": 30,
"email": "john@example.com"
}
"""
// Convert the JSON string to Data
if let jsonData = jsonString.data(using: .utf8) {
do {
// Parse the JSON data into the User model
let user = try JSONDecoder().decode(User.self, from: jsonData)
print("Name: \(user.name), Age: \(user.age), Email: \(user.email ?? "N/A")")
} catch {
print("Error decoding JSON: \(error)")
}
}
I tested with Xcode 16.2 and latest 16.3, it reliably crashes the lldb server!
Swift Playground
RSS for tagLearn and explore coding in Swift through interactive learning experiences on the Swift Playground app for iPadOS and macOS.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
While I am not new to programming, I am quite new to the Swift language. I am using the Swift Playground app on macOS 26 on an M1 MacBook Air.
I am on the lesson about types. Perhaps it's a silly question, but what is a portal? It is never described or pointed out where to find it in the puzzle world. Similarly, the instructions reference a "switch" object without ever defining what it is. I cannot write code to call methods or set properties on objects about which I have no useful information. Can anyone advise, please?
Thank you kindly.
I am trying to complete the "Initializing Your Expert" lesson in the Swift Playground. Below I post just a snippet of the code that I wrote, since no matter how many lines of code I write, the turnLock() method has no effect whatsoever.
let expert = Expert()
/*Create a function that will move the Expert character forward
the specified number of tiles. This will make the program easier to code and less verbose.
*/
func moveExpert(tiles: Int) {
for tile in 1...tiles {
expert.moveForward()
}
}
/*Create a function to make the Expert do an about face, i.e.
orient itself in the opposite direction.
*/
func aboutFace() {
expert.turnRight()
expert.turnRight()
}
expert.turnLockUp()
The instructions give no information about this method, such as when or where it can and cannot be called. It states merely that calling it is supposed to "reveal the path between the platforms." I don't see multiple platforms in the 3D puzzle world, just one platform with different levels.
No "path between platforms" is ever shown when I call this method, regardless of the location of the Expert character. Why doesn't this method ever do anything at all?
Can anyone advise?
Thank you kindly.
Topic:
Developer Tools & Services
SubTopic:
Swift Playground
Hello all!
I am currently facing an issue where I am receiving an "ios app products are only permitted in swift playground packages" error when trying to build the app. I forked a branch from the git repo that my friend made not too long ago, yet I still can't figure out what the issue was. I can provide the repo if needed.
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
Topic:
Developer Tools & Services
SubTopic:
Swift Playground
Tags:
Swift Student Challenge
Swift Playground
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!
Topic:
Developer Tools & Services
SubTopic:
Swift Playground
Can someone help me with this please…
I have two apps which I have updated and have just tried uploading them to the Appstore.
This troubles me because I am paid up to date…
What is the best course of action for me to resolve this please?
I am trying to challenge myself by building an iPhone app in Swift Playgrounds. I just got a Mac Mini M4, so I am trying Swift Playgrounds for Mac.
I can submit a build to TestFlight, but it's for Mac and won't let me even test on my iPhone.
How can I build my app for iPhone?
The least "hacky" answer is appreciated, but I'll entertain anything. Examples in order of hackiness might be:
I missed an option in Playgrounds for Mac.
Open my playground in Xcode, change something, open back in Playgrounds for Mac.
Same as above, but maybe I have to add/copy a file (e.g., manifest.plist).
Open my playground in Playgrounds for iPad (I have an iPad 9), do something, copy back to Playgrounds for Mac.
Submit via Playgrounds for iPad.
Submit via Xcode.
BTW, I'm challenging myself not just for its own sake, but because I'm curious how far a student/newbie/etc can take Swift Playgrounds. I was hoping to set a good example for others looking for a lighter-resource, more user-friendly experience than Xcode (which is why I assume Playgrounds for Mac even exists). But right now it feels like Playgrounds for Mac is a … third-class citizen? Maybe the iPad version is second-class? I haven't really tried it.
P.S. Why does this text editor seem so lame? Making a numbered list and adding to it is a nightmare. Should be: start a numbered list, hit return, new number appears below. I'm on Safari. This should be the best dev experience on the planet, not the worst!
Some reason the image 'Ren' is not being loaded even though it is in the project how can I resolve this issue in Xcode Playgrounds?
I just wonder if it’s possible to add push notifications to an app made it Swift Playgrounds or if it always has to be exported to XCode first
Topic:
Developer Tools & Services
SubTopic:
Swift Playground
Tags:
APNS
Swift Playground
SwiftUI
User Notifications
I am running Swift Playgrounds 4.51 under OSX 14.7 on a Mac mini M2 Pro.
Under App settings for my app, I select "Install on this Mac." I get an error "An error occurred during installation Please check Console.app for further information"
I can't find any entry in the console logs for this.
I have a personal (free) developer account.
Is there a way to create a Finder launchable app with Swift Playgrounds?
I found part of the problem. My main user that I use for "normal" activity does not have administrative rights. If I give that user administrative rights, the create app succeeds and the app is added to the global Applications folder.
Is there a way to have the app added to my User Application folder that then shouldn't require administrative access?
Hello! I would like to use Speech Framework on my App Playground for this year challenge. But I still can't understand if I am allowed to use it to respect the rule of "not rely on a network connection". That's why:
Speech framework can use on-device Speech recognition –
No internet connection needed ✅.
But it can ask to download an Apple's native language package to use it for this on-device recognition – To get this, you need to be connected to the Internet ❌.
When I try to add a Speech Recognition Capabilities on my App Playground, its' description says: "Required to perform speech recognition using Apple's servers." (screenshot is attached). Does it mean that I won't be able to use on-device recognition on my App Playground? – And therefore, only online-version of this framework is available and I can't use it to participate on the challenge successfully❓.
If it's possible, could you please make it clearer? This framework is crucial for my App Playground and I really need this to make it work.
Thanks for your help in advance! And a have a good day!
Hello! I have a quick question about locking orientation and disabling Multitasking/Slide Over in a .swiftpm for the Swift Student Challenge.
A .swiftpm file contains a Package.swift file. At the top of this file, there is a very scary warning that directs you to not edit it. However, being unable to edit this means that I cannot lock the orientation of an iPad and disable Multitasking/Slide Over.
I have read that it does not break your project if you ignore the warning and I tried it out for myself — editing the file does indeed lock orientation and disable Multitasking/Slide Over! Although, as you can imagine, this is quite nerve-wracking.
What are the actual technical implications of doing this? Are participants allowed to do this?
If this does not seem like a good idea, would judges follow through with a note that tells them to simply not use certain orientations and Multitasking/Slide Over? (Yeah, I know… not an ideal thing but if there’s anyone to understand it would be Apple employees).
I am faced with two uncertain options: ignore a warning and get what I need or follow the warning but then have a very poorly designed experience (some apps just aren’t meant for portrait and Multitasking/Slide Over, even if this is not a full app).
I definitely don’t want hundreds of hours of work to go down the drain or risk rejection because of some type of problem with this, that’s for sure. Perhaps a “hack” would work if I were creating an actual app, but the stakes become higher when it is for this challenge.
Thanks! :)
I updated my iPad to iOS 18, but when I went into Swift Playgrounds it only had the iOS 17 SDK.
Maybe it has to with the fact that I’m on an iPad 9th Gen and it doesn’t have the Apple intelligence features so it can’t run the AI features.
I’m just wondering if I will be getting the new SwiftUI features such as the new [TabBar](https://developer.apple.com/videos/play/wwdc2024/10147/) or [MeshGradients.](https://developer.apple.com/videos/play/wwdc2024/10151/?time=381)
Topic:
Developer Tools & Services
SubTopic:
Swift Playground
Thanks for the upgrade, the new project selection screen is nice and I’m happy that the SDK has been updated. But I notices some issues
Since update to 4.6
In an app project, if one of the file contains an error and I select another file. The error is not reported and the upper icon shows a checked mark as if the project contains no compilation errors.
Also, if I’m on the file that contains the error the upper icon turn in red (that is ok) but if I press the icon then the error message, the editor does not jump to the error
It was working fine on the previous version
(I use it on a iPad pro (A12Z) with the latest iPad OS version)
Topic:
Developer Tools & Services
SubTopic:
Swift Playground
Hi, I encountered an issue after the latest update on Swift Playground.
I’m using the iPad Pro 3rd Gen, first time reporting a bug hopefully I’m on the right platform.
When I create a new Swift file or folder, it’ll auto revert the file/folder name to the default naming upon creation.
Tested this one on a few existing projects, it’s the same for all of them.
Initially when I created a new project to verify, those files/folders can be renamed without the issue of reverting.
But after testing it again, seems like the same issue is happening to it as well.
I‘ve tried restarting my iPad but the problem persists.
So I thought to report it and from my search seems like this is the platform for it? Thanks.
I'm unable to rename my Swift Playground or add/change the app icon when I imported a package dependency after upgraded my Swift Playgrounds App to the newest version. Every time I tried to do that, the whole project will be destroyed and showed error message below.
I wonder if anyone have same experience with me or someone can tell me the solution, it terrifies me and I'm worried that I'll be unable to submit my project on time because of that.
Fatal Error in Swift Playground
Description
I'm experiencing a catastrophic error when importing Package Dependency in any Swift Playgrounds that has icon or name that caused the whole Playground won't work anymore with error messages below.
I'm current running macOS Sequoia 15.3 (24D60) and Swift Playgrounds 4.6.1. They're all up-to-date.
Reproduction
Open Swift Playgrounds and and create a new project.
Import a package dependency
https://github.com/simibac/ConfettiSwiftUI.git
Rename the project and add an icon
Then you should able the reproduce the problem. I strongly believed that this is a serious bug.
You'll find that Assets in the left column are disappeared and appeared Assets.xcassets, you're unable to reveal the Dependency in the column like the reference picture above. The whole Playground is destroyed now and unable to work anymore.
Topic:
Developer Tools & Services
SubTopic:
Swift Playground
Tags:
Swift Packages
Swift
Swift Playground
第一次接触swift编程,swift playground里面编程入门挺简单的,因为英语也不好,不知道怎么入手了
Hi, friends!
I have a Keynote file, in which I create design for macOS applications settings and system settings, that I use and which are installed on my Mac.
I like to record my settings so that every time I reinstall the system or an application I can open my file and set it up exactly the way I want. It's like a user manual, only it looks nice with Mac design elements. And I do it in a presentation (Keynote). I also use a Sketch for the design.
I want to turn all this into an app for myself, using Swift Playground.
Does anyone know how to, for example, add a macOS Dock icon from a Sketch to Swift Playground?
Topic:
Developer Tools & Services
SubTopic:
Swift Playground