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

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
637
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
769
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
360
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
401
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
1.9k
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
462
Mar ’23
Swift Playgrounds
Hi everyone At the moment I try to use augmented reality QuickLook in Swift playgrounds When I try to open the reality file from the resource folder, this error shows up. Have someone an idea to fix that problem? Thanks in advance import QuickLook import RealityKit import ARKit struct ARQLViewController: UIViewControllerRepresentable {     func makeUIViewController(context: Context) -> some UIViewController {         return UINavigationController.init(rootViewController: ViewController())     }     func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {} } class ViewController: UIViewController, QLPreviewControllerDataSource {     var isAppeard: Bool = false     override func viewDidLoad() {         super.viewDidLoad()         DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {             let previewController = QLPreviewController()             previewController.dataSource = self             self.present(previewController, animated: true, completion: nil)         }     }    override func viewDidAppear(_ animated: Bool) {         guard !isAppeard else { return }         isAppeard = true         }     func numberOfPreviewItems(in controller: QLPreviewController) -> Int { return 1 }     func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {         guard let path = Bundle.main.path(forResource: "SipARAnimation", ofType: "reality") else { fatalError("Couldn't find the supported input file.") }         let url = URL(fileURLWithPath: path)         return url as QLPreviewItem     } }
0
0
919
Feb ’23
Swift Playground version for macOS 12.6
Hello! I want to become an ios developer. But the problem is that my laptop is quite old and is not up to date with version 12.6.3 (Monterey). Version 4.2.1 is currently available in the app store, which is supported by devices of version 13 and higher. Where can I download the version of Swift playground that my laptop supports? This is probably version 4.1.
0
0
1.2k
Feb ’23
How can I force landscape on a swift playgrounds project?
I only have an iPad, no MacOS or iPhone, and I am attempting to create an app for the apple store. I had originally created this app for Android, and I'm trying to recreate it from scratch using the iPad with Swift Playgrounds. It had been going well enough until I ran into this issue. Most threads point to updating Package.Swift, but this doesn't seem to be an option for me. (see https://developer.apple.com/forums/thread/704249) Is there anyway to do it within the Playgrounds tool? Also, I attempted to submit my app to the app store, but it was rejected due to the appearance in portrait mode.... Yes, it won't look right there. But, without the ability to force landscape, I'm going to have to redesign all my views.
1
0
1.2k
Feb ’23
impossible to transport my code from Swift Playgrounds to App Store connect in the preparation of the app on iPad
Hello, I'm having a problem when I want to export my code from SwiftPlaygrounds on my Ipad to the Connect app store and I'm getting the following error message when preparing my app for export The operation failed could end. (PlaygroundDistribution.Distribution-AppRecordCredentialsProviderError error 1.). Credentialed provider request failed with error: "Unexpected nil property at path: 'Actor/ relationships/providerld' but my account is registered as a developer, I don't understand
3
0
583
Feb ’23
Roll right roll left swift playgrounds
hi guy so not sure if I'm asking this question in the right place but trying to learn to code, complete novice, I'm just at the end of the Lear to code 1 in swift playgrounds and I'm stuck on the roll right roll left challange,if if any one could help me out would really appreciate it,while isBlockedLeft || isBlockedRight { moveForward() if isBlocked && isBlockedRight { turnLeft() } if isBlocked && isBlockedLeft { turnRight() } if isBlocked && !isBlockedRight { turnLeft() } while isOnGem { collectGem() } while isOnClosedSwitch { toggleSwitch() } }}
12
0
25k
Feb ’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
Can the playground call the camera permission?
Can the playground call the camera permission?
Replies
0
Boosts
0
Views
425
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
637
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
769
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
360
Activity
Mar ’23
How can i make an audio visualizer in AR
Is it possible to use the AppleMusic API and MusicKit to make an Audio Visualizer like in the Dynamic Island of iPhone 14 pro in AR
Replies
0
Boosts
1
Views
1.1k
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
401
Activity
Mar ’23
Can i implement this in swift playgrounds? Please Help as i am new to Swift Development.
My Playground ideas is using object detection with ARKit in realtime help create a navigation system for the blind.
Replies
0
Boosts
0
Views
940
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
1.9k
Activity
Mar ’23
What's next after LTC2?
Howdy doodle do: I will be grateful if anyone in the know could tell this noob what am I supposed to attempt after finishing Learn to Code 2 playground? I'm almost there.
Replies
1
Boosts
0
Views
706
Activity
Mar ’23
Hey Apple Why Does Swfit Playgrounds Not Available For ios 15.5 and older?
_i have a iPad that Runs iOS 15.5 i Haven’t install Swfit Playgrounds i only Use Shortcuts 😩_
Replies
1
Boosts
0
Views
522
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
462
Activity
Mar ’23
Trouble creating new app following "Keep going with apps"
Every time I try to implement 'SPCAssessableWindowGroup" into my app it gives me an error even though it's being used in the interactive lesson. Can anybody explain?
Replies
0
Boosts
0
Views
453
Activity
Mar ’23
Swift Playgrounds
Hi everyone At the moment I try to use augmented reality QuickLook in Swift playgrounds When I try to open the reality file from the resource folder, this error shows up. Have someone an idea to fix that problem? Thanks in advance import QuickLook import RealityKit import ARKit struct ARQLViewController: UIViewControllerRepresentable {     func makeUIViewController(context: Context) -> some UIViewController {         return UINavigationController.init(rootViewController: ViewController())     }     func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {} } class ViewController: UIViewController, QLPreviewControllerDataSource {     var isAppeard: Bool = false     override func viewDidLoad() {         super.viewDidLoad()         DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {             let previewController = QLPreviewController()             previewController.dataSource = self             self.present(previewController, animated: true, completion: nil)         }     }    override func viewDidAppear(_ animated: Bool) {         guard !isAppeard else { return }         isAppeard = true         }     func numberOfPreviewItems(in controller: QLPreviewController) -> Int { return 1 }     func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {         guard let path = Bundle.main.path(forResource: "SipARAnimation", ofType: "reality") else { fatalError("Couldn't find the supported input file.") }         let url = URL(fileURLWithPath: path)         return url as QLPreviewItem     } }
Replies
0
Boosts
0
Views
919
Activity
Feb ’23
Swift Playground version for macOS 12.6
Hello! I want to become an ios developer. But the problem is that my laptop is quite old and is not up to date with version 12.6.3 (Monterey). Version 4.2.1 is currently available in the app store, which is supported by devices of version 13 and higher. Where can I download the version of Swift playground that my laptop supports? This is probably version 4.1.
Replies
0
Boosts
0
Views
1.2k
Activity
Feb ’23
How can I force landscape on a swift playgrounds project?
I only have an iPad, no MacOS or iPhone, and I am attempting to create an app for the apple store. I had originally created this app for Android, and I'm trying to recreate it from scratch using the iPad with Swift Playgrounds. It had been going well enough until I ran into this issue. Most threads point to updating Package.Swift, but this doesn't seem to be an option for me. (see https://developer.apple.com/forums/thread/704249) Is there anyway to do it within the Playgrounds tool? Also, I attempted to submit my app to the app store, but it was rejected due to the appearance in portrait mode.... Yes, it won't look right there. But, without the ability to force landscape, I'm going to have to redesign all my views.
Replies
1
Boosts
0
Views
1.2k
Activity
Feb ’23
Swift playgrounds and .reality file
In Swift Playgrounds I wrote a simple playgrounds where I want to load a .reality file. How can I do that? From iCloud it doesn't load it correctly.
Replies
0
Boosts
0
Views
651
Activity
Feb ’23
impossible to transport my code from Swift Playgrounds to App Store connect in the preparation of the app on iPad
Hello, I'm having a problem when I want to export my code from SwiftPlaygrounds on my Ipad to the Connect app store and I'm getting the following error message when preparing my app for export The operation failed could end. (PlaygroundDistribution.Distribution-AppRecordCredentialsProviderError error 1.). Credentialed provider request failed with error: "Unexpected nil property at path: 'Actor/ relationships/providerld' but my account is registered as a developer, I don't understand
Replies
3
Boosts
0
Views
583
Activity
Feb ’23
Roll right roll left swift playgrounds
hi guy so not sure if I'm asking this question in the right place but trying to learn to code, complete novice, I'm just at the end of the Lear to code 1 in swift playgrounds and I'm stuck on the roll right roll left challange,if if any one could help me out would really appreciate it,while isBlockedLeft || isBlockedRight { moveForward() if isBlocked && isBlockedRight { turnLeft() } if isBlocked && isBlockedLeft { turnRight() } if isBlocked && !isBlockedRight { turnLeft() } while isOnGem { collectGem() } while isOnClosedSwitch { toggleSwitch() } }}
Replies
12
Boosts
0
Views
25k
Activity
Feb ’23
Beginner: no playground on Xcode 12
I can't see the option to start a playground on Xcode 12, am I doing something wrong? thanks,
Replies
6
Boosts
2
Views
8.1k
Activity
Feb ’23