Swift Playground

RSS for tag

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

Swift Playground Documentation

Posts under Swift Playground subtopic

Post

Replies

Boosts

Views

Activity

Difficulty running CoreML model in new Swift Playground app
Hi everyone, I'm having trouble running a CoreML model in the new Swift Playground app. I trained and exported the model from CreateML, saved it as a .mlmodel file, and then dragged it into the Xcode project of my playground. However, the model class wasn't generated automatically, so I put the model in a different project and copied the class over. Despite this, the model still doesn't run - Xcode can't find the compiled source (mlmodelc). To try and fix this, I compiled the model in another project and then dragged the mlmodelc folder over to the playground project. However, Xcode still couldn't build, saying that there was no available target. I'm not sure what to do next - the model works fine in another normal Xcode project. Any help or advice would be greatly appreciated! Let me know if you need more information. Thanks in advance!
1
0
1.5k
Apr ’23
Core ML in Swift Playground
I wanted to create an App that utilizes the Vision Framework for the 2023 Swift Student Challenge. From the few post regarding the topic I tried to create a dummy project and build it to create a mlmodelc-file that I copied into the recourses folder and copied the automatically generated swift code into the source folder. Somehow the playground crashes when trying to force-unwrap the URL, which means it cannot find the model file (I also tried the same with an mlmodel file). class var urlOfModelInThisBundle: URL { let resPath = Bundle(for: self).url(forResource: "FoodClassifier", withExtension: "mlmodel") /* Here it fails already */ return try! MLModel.compileModel(at: resPath) } The naming is accurate and the dummy app is working. Is there something that I am not seeing?
4
1
1.9k
Apr ’23
Questions when working with a Swift Playgrounds App
Hi All. This is my first year for applying for the WWDC23 Swift Student challenge. I have some questions regarding a Swift Playgrounds App: How to I access the Info.plist file for the application so I can add the correct usage description for using the on-device camera. How can I use core data? Seems like it is not allowed within a Swift Playgrounds App. Would submitting an Xcode project jeopardize my submission since I'm having such trouble? Thank you
1
1
1.5k
Apr ’23
App Preview problem in Playgrounds for macOS
Hi there! I'm having some trouble while developing my Playground for the Swift Student Challenge for the WWDC23. The thing is that my app is more oriented to iPhone and the App Preview that Playgrounds offers is for macOS, so the app isn't working as it should. Is there any way to create a Playground (swiftpm file) with the iPhone preview? Thanks, Hugo.
1
0
671
Apr ’23
Adding pictures as comments in Playground
Hello, Anyone knows how to add photos "like a comment" would be really appreciated. I would want to provide a photo as an example rather than a comment to a function. I attempted to: /// ! [ ] (file:///Resources/myImage.jpg) or /*: ! [ Alt text ]( image_filename .png "Optional title") */ however I was unable to get it to work; the playground will not display it.
0
0
980
Apr ’23
Scrumdinger CardView .previewLayout does not work
Hi all, my code looks like: import SwiftUI struct CardView: View {     let scrum: DailyScrum     var body: some View {         Text(scrum.title)             .font(.headline)     } } struct CardView_Previews: PreviewProvider {     static var scrum = DailyScrum.sampleData[0]     static var previews: some View {         CardView(scrum: scrum)             .background(scrum.theme.mainColor)             .previewLayout(.fixed(width: 400, height: 60))     } } In web tutorial .previewLayout(.fixed(width: 400, height: 60)) is changing size of the preview. But not for me, I still have full size preview and with adding Spacer() like this: struct CardView: View { let scrum: DailyScrum var body: some View { VStack(alignment: .leading) { Text(scrum.title) .font(.headline) Spacer() HStack { Label("\(scrum.attendees.count)", systemImage: "person.3") } } } } the body will grow across whole phone preview. Where am I wrong please ?
3
0
1.2k
Apr ’23
Object-C Packages [ Swift Playgrounds ]
I have been working on an app for messaging and storing information. Such as documents, Images, Calendars, etc. I have moved to the Swift Playgrounds because my friend is helping build the app, but he has an iPad, So I moved the app over to playgrounds so we can collaborate. I cannot import Firebase into my project, every time I do, Playgrounds crashes. I have found this thread on GitHub that was having the same issue, it has been over a year since this was open, are we ever going to get the ability to use non pure swift packages? Is there any work around to this? I have been searching for 2 days of other database options, but there are non that work. https://github.com/firebase/firebase-ios-sdk/issues/9107 Dec 16, 2021
2
0
654
Apr ’23
AR Quick Look doesn't work in Swift Playgrounds
Hey everyone, I have a question regarding AR Quick Look, I have a simple view with an ARQLView showing a .usdz file of a Nike shoe. This code works perfectly fine on my iPad if I sideload the app using Xcode. The problem is, when I try to use the same code in Swift Playgrounds on the iPad, it gives the same view but with the "AR" mode grayed out, with the "Object" mode the only option. So I can pan and zoom the 3D model but I cannot see it in AR. Is this a limitation of Playgrounds, or is Playgrounds itself encountering a bug (which isn't uncommon in my experience). Screenshot of app sideloaded with Xcode, then Playgrounds: https://imgur.com/a/FCE0lYh
0
0
790
Mar ’23
in swiftplay ground
Hello i’m SwiftPlayground newby. in swiftplayground while !isBlocked { while !isBlocked { moveForward()} turnRight()} i did this code in 2 coner way(here is the picture in down) and the robot turn right when he is blocked. but the code is ‘while !isBlocked {turnRight()}’. why this code works likes this?
0
0
368
Mar ’23
[Mac] Playground courses won't update to Swift version 5.7
Hi, I'm using a MacBook Pro with the latest macOS 13.2.1. I would like to download the updated courses in Swift Playgrounds which are version 5.7 For some reason it's downloading the courses but only in version 5.3. Did these courses actually receive an update for Swift 5.7, or did they simply write Swift 5.7 next to the course, but all the syntax is the same as Swift 5.3? Any idea how to fix it? Playgrounds Version 4.2.1 (1726.28) Thanks!😊
0
1
421
Mar ’23
Problem mit text classifier model
Hi, ich habe nach folgender Anleitung versucht ein Text classifier model zu machen.Allerdings scheitert dies daran, das die evaluation() Funktion nicht funktioniert.Den Error den ich (in SwiftPlayground) bekomme ist: No exact matches in call to instance method 'evaluation' Hier ist der Code, den ich verwende: if #available(iOSApplicationExtension 15.0, *) {         let data = try! MLDataTable(contentsOf:  fileLiteral(resourceName: "TestData.json"))          let (trainingData, testingData) = data.randomSplit(by: 0.8, seed: 5)                  let sentimentClassifier = try! MLTextClassifier(trainingData: trainingData,                                                        textColumn: "text",                                                        labelColumn: "label")         // Training accuracy as a percentage         let trainingAccuracy = (1.0 - sentimentClassifier.trainingMetrics.classificationError) * 100         // Validation accuracy as a percentage         let validationAccuracy = (1.0 - sentimentClassifier.validationMetrics.classificationError) * 100         let evaluationMetrics = sentimentClassifier.evaluation(on: testingData)//Error hier         let evaluationAccuracy = (1.0 - evaluationMetrics.classificationError) * 100                  let metadata = MLModelMetadata(author: "No One",                                        shortDescription: "A model trained to classify movie review sentiment",                                        version: "1.0")         try! sentimentClassifier.write(to: URL(fileURLWithPath: Bundle.main.path(forResource: "MODEL", ofType: "mlmodel")!),                                       metadata: metadata)     } else {         print("dein Gerät erfüllt nicht die Bedingungen für dieses Programm")     } vielen Dank im Voraus (:
1
0
2.1k
Mar ’23
Submit app to Testflight
Hi everybody I created my first app with Swift Playgrouds on my iPad. Don‘t have xCode or a Mac. Now I want to test the app on my iPhone, without enrolling for the 99$ Apple Developer Program. My questions: Is it possible to submit the App to Testflight, directly from Swift Playgrounds? If yes, how? “Upload to App Store Connect“ does not work, as I don‘t know how to create a Team. How can I create Teams without an having a App Store Connect account? Thanx for any HELP and Best Greetings from Germany Jorg
0
1
482
Mar ’23
Difficulty running CoreML model in new Swift Playground app
Hi everyone, I'm having trouble running a CoreML model in the new Swift Playground app. I trained and exported the model from CreateML, saved it as a .mlmodel file, and then dragged it into the Xcode project of my playground. However, the model class wasn't generated automatically, so I put the model in a different project and copied the class over. Despite this, the model still doesn't run - Xcode can't find the compiled source (mlmodelc). To try and fix this, I compiled the model in another project and then dragged the mlmodelc folder over to the playground project. However, Xcode still couldn't build, saying that there was no available target. I'm not sure what to do next - the model works fine in another normal Xcode project. Any help or advice would be greatly appreciated! Let me know if you need more information. Thanks in advance!
Replies
1
Boosts
0
Views
1.5k
Activity
Apr ’23
Core ML in Swift Playground
I wanted to create an App that utilizes the Vision Framework for the 2023 Swift Student Challenge. From the few post regarding the topic I tried to create a dummy project and build it to create a mlmodelc-file that I copied into the recourses folder and copied the automatically generated swift code into the source folder. Somehow the playground crashes when trying to force-unwrap the URL, which means it cannot find the model file (I also tried the same with an mlmodel file). class var urlOfModelInThisBundle: URL { let resPath = Bundle(for: self).url(forResource: "FoodClassifier", withExtension: "mlmodel") /* Here it fails already */ return try! MLModel.compileModel(at: resPath) } The naming is accurate and the dummy app is working. Is there something that I am not seeing?
Replies
4
Boosts
1
Views
1.9k
Activity
Apr ’23
Questions when working with a Swift Playgrounds App
Hi All. This is my first year for applying for the WWDC23 Swift Student challenge. I have some questions regarding a Swift Playgrounds App: How to I access the Info.plist file for the application so I can add the correct usage description for using the on-device camera. How can I use core data? Seems like it is not allowed within a Swift Playgrounds App. Would submitting an Xcode project jeopardize my submission since I'm having such trouble? Thank you
Replies
1
Boosts
1
Views
1.5k
Activity
Apr ’23
App Preview problem in Playgrounds for macOS
Hi there! I'm having some trouble while developing my Playground for the Swift Student Challenge for the WWDC23. The thing is that my app is more oriented to iPhone and the App Preview that Playgrounds offers is for macOS, so the app isn't working as it should. Is there any way to create a Playground (swiftpm file) with the iPhone preview? Thanks, Hugo.
Replies
1
Boosts
0
Views
671
Activity
Apr ’23
Adding pictures as comments in Playground
Hello, Anyone knows how to add photos "like a comment" would be really appreciated. I would want to provide a photo as an example rather than a comment to a function. I attempted to: /// ! [ ] (file:///Resources/myImage.jpg) or /*: ! [ Alt text ]( image_filename .png "Optional title") */ however I was unable to get it to work; the playground will not display it.
Replies
0
Boosts
0
Views
980
Activity
Apr ’23
Scrumdinger CardView .previewLayout does not work
Hi all, my code looks like: import SwiftUI struct CardView: View {     let scrum: DailyScrum     var body: some View {         Text(scrum.title)             .font(.headline)     } } struct CardView_Previews: PreviewProvider {     static var scrum = DailyScrum.sampleData[0]     static var previews: some View {         CardView(scrum: scrum)             .background(scrum.theme.mainColor)             .previewLayout(.fixed(width: 400, height: 60))     } } In web tutorial .previewLayout(.fixed(width: 400, height: 60)) is changing size of the preview. But not for me, I still have full size preview and with adding Spacer() like this: struct CardView: View { let scrum: DailyScrum var body: some View { VStack(alignment: .leading) { Text(scrum.title) .font(.headline) Spacer() HStack { Label("\(scrum.attendees.count)", systemImage: "person.3") } } } } the body will grow across whole phone preview. Where am I wrong please ?
Replies
3
Boosts
0
Views
1.2k
Activity
Apr ’23
Object-C Packages [ Swift Playgrounds ]
I have been working on an app for messaging and storing information. Such as documents, Images, Calendars, etc. I have moved to the Swift Playgrounds because my friend is helping build the app, but he has an iPad, So I moved the app over to playgrounds so we can collaborate. I cannot import Firebase into my project, every time I do, Playgrounds crashes. I have found this thread on GitHub that was having the same issue, it has been over a year since this was open, are we ever going to get the ability to use non pure swift packages? Is there any work around to this? I have been searching for 2 days of other database options, but there are non that work. https://github.com/firebase/firebase-ios-sdk/issues/9107 Dec 16, 2021
Replies
2
Boosts
0
Views
654
Activity
Apr ’23
AR Quick Look doesn't work in Swift Playgrounds
Hey everyone, I have a question regarding AR Quick Look, I have a simple view with an ARQLView showing a .usdz file of a Nike shoe. This code works perfectly fine on my iPad if I sideload the app using Xcode. The problem is, when I try to use the same code in Swift Playgrounds on the iPad, it gives the same view but with the "AR" mode grayed out, with the "Object" mode the only option. So I can pan and zoom the 3D model but I cannot see it in AR. Is this a limitation of Playgrounds, or is Playgrounds itself encountering a bug (which isn't uncommon in my experience). Screenshot of app sideloaded with Xcode, then Playgrounds: https://imgur.com/a/FCE0lYh
Replies
0
Boosts
0
Views
790
Activity
Mar ’23
in swiftplay ground
Hello i’m SwiftPlayground newby. in swiftplayground while !isBlocked { while !isBlocked { moveForward()} turnRight()} i did this code in 2 coner way(here is the picture in down) and the robot turn right when he is blocked. but the code is ‘while !isBlocked {turnRight()}’. why this code works likes this?
Replies
0
Boosts
0
Views
368
Activity
Mar ’23
[Mac] Playground courses won't update to Swift version 5.7
Hi, I'm using a MacBook Pro with the latest macOS 13.2.1. I would like to download the updated courses in Swift Playgrounds which are version 5.7 For some reason it's downloading the courses but only in version 5.3. Did these courses actually receive an update for Swift 5.7, or did they simply write Swift 5.7 next to the course, but all the syntax is the same as Swift 5.3? Any idea how to fix it? Playgrounds Version 4.2.1 (1726.28) Thanks!😊
Replies
0
Boosts
1
Views
421
Activity
Mar ’23
Problem mit text classifier model
Hi, ich habe nach folgender Anleitung versucht ein Text classifier model zu machen.Allerdings scheitert dies daran, das die evaluation() Funktion nicht funktioniert.Den Error den ich (in SwiftPlayground) bekomme ist: No exact matches in call to instance method 'evaluation' Hier ist der Code, den ich verwende: if #available(iOSApplicationExtension 15.0, *) {         let data = try! MLDataTable(contentsOf:  fileLiteral(resourceName: "TestData.json"))          let (trainingData, testingData) = data.randomSplit(by: 0.8, seed: 5)                  let sentimentClassifier = try! MLTextClassifier(trainingData: trainingData,                                                        textColumn: "text",                                                        labelColumn: "label")         // Training accuracy as a percentage         let trainingAccuracy = (1.0 - sentimentClassifier.trainingMetrics.classificationError) * 100         // Validation accuracy as a percentage         let validationAccuracy = (1.0 - sentimentClassifier.validationMetrics.classificationError) * 100         let evaluationMetrics = sentimentClassifier.evaluation(on: testingData)//Error hier         let evaluationAccuracy = (1.0 - evaluationMetrics.classificationError) * 100                  let metadata = MLModelMetadata(author: "No One",                                        shortDescription: "A model trained to classify movie review sentiment",                                        version: "1.0")         try! sentimentClassifier.write(to: URL(fileURLWithPath: Bundle.main.path(forResource: "MODEL", ofType: "mlmodel")!),                                       metadata: metadata)     } else {         print("dein Gerät erfüllt nicht die Bedingungen für dieses Programm")     } vielen Dank im Voraus (:
Replies
1
Boosts
0
Views
2.1k
Activity
Mar ’23
Submit app to Testflight
Hi everybody I created my first app with Swift Playgrouds on my iPad. Don‘t have xCode or a Mac. Now I want to test the app on my iPhone, without enrolling for the 99$ Apple Developer Program. My questions: Is it possible to submit the App to Testflight, directly from Swift Playgrounds? If yes, how? “Upload to App Store Connect“ does not work, as I don‘t know how to create a Team. How can I create Teams without an having a App Store Connect account? Thanx for any HELP and Best Greetings from Germany Jorg
Replies
0
Boosts
1
Views
482
Activity
Mar ’23