Hi.
I want to make my Playground Book public.
How can I prepare and provide Swift Playgrounds subscription server?
Thanks.
Swift Playgrounds
RSS for tagLearn and explore coding in Swift through interactive learning experiences on the Swift Playgrounds app for iPadOS and macOS.
Posts under Swift Playgrounds tag
94 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
I'm trying to create a simple Regex Builder to parse a timestamp in hh:mm:ss or mm:ss format, a " - " separator, and then a string. I'm trying to use the new Swift RegexBuilder however it doesn't seem to work. It compiles but crashes when running when trying to get the text portion.
Example code in a single playground preview file for reference:
import SwiftUI
import RegexBuilder
struct RegexTestView: View {
var string: String {
let timecode = Regex {
Optionally {
OneOrMore(.whitespace)
}
// timecode section
Optionally {
Capture {
OneOrMore(.digit)
} transform: { match in
Int(match)
}
":"
}
TryCapture {
OneOrMore(.digit)
} transform: { match in
Int(match)
}
":"
// seconds
TryCapture {
OneOrMore(.digit)
Optionally { // miliseconds
"."
OneOrMore(.digit)
}
} transform: { match in
TimeInterval(match)
}
// separator
" - "
Capture { // WHY CAN'T I GET THE REMAINING TEXT???? Any attempts I make to get this result in a crash.
OneOrMore(.any)
} transform: { match in
String(match)
}
}
let tests = [" 222:45:23.2 - foo","2:34:22 - bar"," 2:08 - baz","2:32.18","2:45:23.2 - what"]
var results = ""
for test in tests {
guard let match = test.wholeMatch(of: timecode) else {
results += "MATCH NOT FOUND"
continue
}
results += """
••••
\(match.0)
\(String(describing: match.1))
\(String(describing: match.2))
\(String(describing: match.3))
"""
/*
// Adding this line to the above crashes
\(String(describing: match.4))\n
*/
}
return results
}
var body: some View {
Text(string)
}
}
#Preview("Regex") {
RegexTestView()
}
I wanted to take some code I had written in an Xcode project and put it in a playground, though while working on a playground in Xcode, it's showing errors that some lines of code are only supported in iOS 17. I'm updated to the most recent version. Is there any reason why my playgrounds are showing this error?
I assume it might be due to the playground wanting to make sure the app works on older OSs, but a lot of the code I used has no previous counterpart. If this is the case, is there any way I can get around this?
Thanks for taking the time to check this out.
Is there a specific name I need to rename the MyPlayground file in order to submit it to the WWDC Swift Student Challenge?
When I open a new blank playground in Xcode the very first line "import cocoa" gets the alert "Could not build Objective-C module 'Cocoa'". Can someone please tell me what I have done wrong and how I can fix it.
Xcode 15.0.1
Ventura 13.6.1
Hi there,
I am trying to add functionalities for my app developed using Swift Playgrounds environment on mac.
There is a plus button that opens an interface where I can choose the feature in question.
Until here, no problem you would say!
But my problem is that I don’t know which package should I use or even import to develop my application?
Best regards,
Have downloaded playgrounds 4.3 to my iPad Air running ipados 16.5.
Trying to use playground “Get started with Apps” but receiving message “Unsupported file format Get Started with Apps.swiftpm cannot be opened in Swift Playgrounds”.
I do not have Mac or windows PC so am stuck! Help ??
Hi,
I have a problem with making a swift playgrounds app walkthrough. I followed the steps exactly and modified my Package.swift a bit (in the targets section):
.executableTarget(name: "App", dependencies: ["Guide"], path: "App"),
.target(
name: "Guide",
path: "Guide",
resources: [
.process("Guide.tutorial"),
])
Now when I open the project in Playgrounds I get this error:
public headers ("include") directory path for 'Guide' is invalid or not contained in the target
Any help would be appreciated.
Thanks
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)
}
}
}
All our custom Playground Books using SpriteKit stopped working after upgrading to SwiftPlaygrounds version 4.4
To reproduce the issue, simply create a new book by clicking the top right hand icon and in the book add two lines of code.
import SpriteKit
let circle = SKShapeNode(circleOfRadius: 100.0)
The second line produces an error. I tried with other classes. SKAction seems to work. SKSpriteNode, SKTexture etc have the same issue. Please help. Our students are stuck!
At the moment with my app Users have to go to Privacy & Security -> Locations Services -> On -> Scroll down to my app and turn on their Location Preference.
I am trying to incorporate in to my app the Code below to make it unecessary to leave the app to enable the User‘s location to be displayed but it does not work.
Please tell me, what am I missing here?
import MapKit
import SwiftUI
import CoreLocation
// Prompt User to choose Location Preference //
class ViewController: UIViewController, CLLocationManagerDelegate{
var locationManager: CLLocationManager?
override func viewDidLoad() {
super.viewDidLoad()
locationManager = CLLocationManager()
locationManager?.delegate = self
locationManager?.requestWhenInUseAuthorization()
view.backgroundColor = .gray
}
}
// The rest of the Code which is working okay ( Map etc.) //
struct Positions: Identifiable {
let id = UUID()
let name: String
let latitude: Double
let longitude: Double
var coordinate: CLLocationCoordinate2D {
CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
}
}
etc.
etc.
Is there a way of deleting an app from the Location Services in the Privacy Setting?
Despite deleting the particular app evidence of it remains.
Also with a particular app there are several of the same in the list. I do understand there may be one for the Playgrounds version and one for the actual downloaded version but I have more.
Is there a way of starting with a clean slate?
Hi, dear community, I recently updated my old Macbook pro(model 2016) to Monterey(which is the latest macOS that support 2016 model), but the Swift Playgrounds on AppStore requires macOS 13. Is there any way I can get the app, just like Xcode? Xcode provides an alternative way to download the xip file of an older version, but playgrounds does.
Many thanks in advance, any help will be appreciated!
Since Swift Playgrounds was able to submit Apps to the AppStore ,Apple stated that it can be used to develop apps without having to use Xcode.
But if you do so you are lost:
The Testflight beta versions of Swift Playgrounds with API support for iOS 17 and macOS 14 have expired one week before the new systems become/became available and there is still no final version!
If you used Playgrounds to develop an iOS 17 ready version of your app you can't do anything now and that at a time where the users get their hands on the new OS.
That is really bad.
I have the latest version on macOs and Xcode, since the last update playgrounds doesn't work, the code compiles and runs but the run console doesn't show up and it stucks with the loading icon.
before the last update it worked fine
This is my first app and I'm very new to coding. I started out with enthusiasm until becoming overwhelmed with Swift coding language...
The app I'm trying to design is very simple and will go hand in hand with the work I do. I attached a screenshot of the UI of what I'm trying to achieve.
All I need the app to do is to let me input the appropriate information, and save it to the table.
The problem is that:
Swift doesn't import source files like C#, whenever I create a new swift file and try to import the file called User.swift, "no file exists named User"
I've looked all over and the examples I'm seeing don't make sense, I dont understand why Xcode/Playground doesn't see it.
Instead of using the UI, I'm writing out:
TextField(Name, text: ???)
I've tried defining a variable in my User.swift file (I can't import which might be the problem).
Even if I could import the User.swift file, I'm not even sure of what would go after the "text:____" spot - I've tried using the $name or changing it to "self.name" and there's always a problem
I realize this may be trivial to some of you but I appreciate your input.
What I'm writing in my User.swift file:
import SwiftUI
struct User {
var name: String
var phone: String
var company: String
var userid: String
var clientid: String
var errorid: String
var notes: String
init(name: String, phone: String, company: String, userid: String, clientid: String, errorid: String, notes: String) {
self.name = name
self.phone = phone
self.company = company
self.userid = userid
self.clientid = clientid
self.errorid = errorid
self.notes = notes
}
}
Sound Pad throws an error on the audio device on iPad.
Sound Pad
Version 1.0.0
3 April 2023
Swift 5.8 Edition
A fatal error was found in AudioPlayer.swift
Line which causes this
var engine: AVAudioEngine
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!
I'm using the latest Playground app (version 4.3.1) and Xcode 15. I'd like to practice code that supports iOS 12 and above. Is there a way to set the deployment target in either the standalone Playground app or within Xcode playgrounds?
Hello my friends, I am using a Macbook Air M2 chip. After the MacOS Sonoma update, Xcode started to work very slowly. I installed Xcode beta. It still takes 30 minutes to build even the same line of code. Does anyone have an idea for a solution? 🥲