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

200 Posts

Post

Replies

Boosts

Views

Activity

Wrong colours when rendering SKTexture
I am generating an SKTexture with a GKNoiseMap. When I look at the texture in a swift playground, it has the expected colours. But when I apply the texture to a material and render it in a SCNView, the colours are different (colours appear too bright). What am I doing wrong? Swift playground to reproduce the issue (look at the texture variable in the playground and compare to rendered image). - https://developer.apple.com/forums/content/attachment/68210adc-98e9-4984-bca7-01f6e658d555
4
1
1.5k
Aug ’24
XCode Previews
Hello... for some reason, XCode previews are no longer working for me. It was working fine a week ago, however, now no matter ho many times i reboot or restart my computer, the preview won't load. The preview is stuck on "loading Preview" no matter how long I wait. I ran the same files on swift playgrounds and the preview works fine there, but not on XCode. I ran both my project and a completely new, unedited project and both will not preview- so I know it is not a problem with my file. Also, the second I open the app the preview pauses. Either way, I don't think an app with only one file should take so long to build...
2
1
865
Jul ’24
Swift playgrounds - (issue with code setup)
hi im fairly new to coding.. about a month, just so u know.. 😇 I am going through the tasks in (Swift Playgrounds) and I am currently in (Learning to code 2) the chapter is (Random gems everywhere) and I tried every possible solution to complete it, but to no avail! any suggestions, comments, or corrections or tips, would be greatly appreciated! I will attach some screenshots for a reference of what I'm trying to accomplish..
0
0
798
Jul ’24
Get Started with Apps Stuck in Playgrounds
The “Get Started with Apps” in Playgrounds looks great but it won’t allow me to advance to the next activity. It seems to think that my solution is incorrect, but what I did matches the solution provided in the “hint.” This could be corrected by either allowing for more variety in the responses, or by allowing the user to advance to the next activity regardless of whether the response they provided was correct.
11
2
3.9k
Jul ’24
Swift Playgrounds 4.1 keeps crashing when rerunning code
Try to learn some Swift coding but Playgrounds keeps crashing. I run Playgrounds 4.1 on latest Monterey 12.7.5, from a MacBook Air dated back 2017. Part of the error log says: Thread 9 Crashed:: Dispatch queue: com.apple.UIKit._UIViewServiceInterfaceConnectionRequest com.apple.PlaygroundsMac.ExecutionExtension The error can be reproduced by re-running the code; Everything goes well when the code was run at first time, but is doomed to fail at second run. Any help?
1
1
1.1k
May ’24
Playgrounds
I've noticed Playgrounds crashing a lot lately, both on iPad and Mac. I have many Macs, Intel & M1, and 2 iPads, 7th Gen and 10.5" Pro. It's noticeably sluggish at the best of times progressively getting worse the last few updates, but worse than that it is hard crashing, losing data in the process. Anyone else seeing this? Not the end of the world, I'm a dev and use Xcode for anything substantial but I like to use Playgrounds on the iPad sometimes when I want to pop a quick idea down. I also plan to start creating playgrounds to help kids get into programming, so hoping this useful app isn't being neglected.
2
0
1.1k
Apr ’24
How do you include custom symbol resources in a package?
I am trying to include custom symbol resources in a swift package for use in other projects. I have read the documentation here: https://developer.apple.com/documentation/xcode/bundling-resources-with-a-swift-package However there is no example code and I have created a very simple project to try and get this working but it does not. .target( name: "TestLibrary", resources: [.process("Resources/Media.xcassets")] ), This is in the Package.swift file and the path relative to the Package.swift file is Sources/TestLibrary/Resources/Media.xcassets. There's a GitHub project with an example custom SF Symbol SVG (but this may not be available in the future): https://github.com/kudit/TestLibrary Including this as a package in a blank Swift Playgrounds App project and just importing the TestLibrary and including TestImageView() in the ContentView technically works (it shows the system full star image, but none of the ways of rendering the test symbol as recommended works. It does work for a few of the options in the #Preview when viewing the project in Xcode. Anyone have any suggestions or know how to get the resources to be accessible from outside the module? I have tried both the .copy( option as well as the .process( option and neither seem to work.
1
0
1.3k
Apr ’24
Playground can not create newbook / download sample playground after iCloud folder deletion, but it crashes
Hello All, I happen to remove "Playgrounds" folder from my iCloud drive, and afterwards Playground is no longer functioning but repeatedly crashes. It was okey before deletion, but now any operation to create or download playground then Playground App crashes all the time. Issue not resolved even creating same name folder by manual, Issue not resolved even re-install Playground - folder in iCloud will not created. I guess I need to fully uninstall PlayGround completely, then start from scratch to let Playground App to hold init step to generate required folder in iCloud, but not sure how to do it. Please give kind help if anyone knows about this issue, or if anyone knows complete deletion step of Playground. Best wishes, tons of thanks in advance. Best Regards, Issey Hamada
2
0
967
Mar ’24
NavigationPath(_items: SwiftUI.NavigationPath.(unknown context at
I tried to use navigationstack, and it works. but couldn't print the path, and with the message: " NavigationPath(_items: SwiftUI.NavigationPath.(unknown context at $7ff84b690a28).Representation.eager([SwiftUI.(unknown context at $7ff84b6907f0).CodableItemBox<Swift.String>]), subsequentItems: [], iterationIndex: 0). " `import SwiftUI var toDos: [String] = [ "list1", "list2", "list3" ] struct ContentView: View { @State private var path = NavigationPath() var body: some View { NavigationStack(path: $path) { List { ForEach(toDos, id:\.self) { toDo in Button(action: { path.append(toDo) print(path) }, label: { Text("go to " + toDo) }) } } .navigationDestination(for: String.self) { toDo in Text("page for " + toDo) } } } } #Preview { ContentView() }` I tried navigationlink and simulator still works fine, but cannot print anything of path
0
0
935
Mar ’24
App Download Size Nag Email - "Universal" device type
Whenever we submit a new release to the App Store we get a nag email from Apple that states, "The app binary listed below was 199.2 MB when you submitted it, but will be 223.9 MB once processed for the App Store. This exceeds the cellular network download size limit and may require your app to be downloaded over Wi-Fi." However, when I download the app from the App Store and have the Settings set to "Alway Ask" on my phone the alert shows 129 MB, which is matches up closely with what we see in the TestFlight metadata for all device types except "Universal". What is "Universal" device type in these days of thinning? And why is Apple apparently using that number to generate the nag email?
0
1
954
Mar ’24
Wrong colours when rendering SKTexture
I am generating an SKTexture with a GKNoiseMap. When I look at the texture in a swift playground, it has the expected colours. But when I apply the texture to a material and render it in a SCNView, the colours are different (colours appear too bright). What am I doing wrong? Swift playground to reproduce the issue (look at the texture variable in the playground and compare to rendered image). - https://developer.apple.com/forums/content/attachment/68210adc-98e9-4984-bca7-01f6e658d555
Replies
4
Boosts
1
Views
1.5k
Activity
Aug ’24
Why can't run xcode on the ipad pro
now,ipad pro has M4.It support Swift Playgrounds,but must be built with a minimum of Xcode 15? Why still need a mac, when I want to develop an ipad app!
Replies
0
Boosts
1
Views
613
Activity
Aug ’24
XCode Previews
Hello... for some reason, XCode previews are no longer working for me. It was working fine a week ago, however, now no matter ho many times i reboot or restart my computer, the preview won't load. The preview is stuck on "loading Preview" no matter how long I wait. I ran the same files on swift playgrounds and the preview works fine there, but not on XCode. I ran both my project and a completely new, unedited project and both will not preview- so I know it is not a problem with my file. Also, the second I open the app the preview pauses. Either way, I don't think an app with only one file should take so long to build...
Replies
2
Boosts
1
Views
865
Activity
Jul ’24
Swift playgrounds - (issue with code setup)
hi im fairly new to coding.. about a month, just so u know.. 😇 I am going through the tasks in (Swift Playgrounds) and I am currently in (Learning to code 2) the chapter is (Random gems everywhere) and I tried every possible solution to complete it, but to no avail! any suggestions, comments, or corrections or tips, would be greatly appreciated! I will attach some screenshots for a reference of what I'm trying to accomplish..
Replies
0
Boosts
0
Views
798
Activity
Jul ’24
Swift Playgrounds 4.5.1 creating new book with Swift 5.9?
Hi all! I am using Swift Playgrounds 4.5.1 on Mac and iPad. When I create new book, they both create new book with Swift 5.9 (instead of Swift 5.10). Is this a bug? The release notes says since 4.5.0 the Swift version has been upgraded to 5.10. Thanks B
Replies
1
Boosts
0
Views
1k
Activity
Jul ’24
Get Started with Apps Stuck in Playgrounds
The “Get Started with Apps” in Playgrounds looks great but it won’t allow me to advance to the next activity. It seems to think that my solution is incorrect, but what I did matches the solution provided in the “hint.” This could be corrected by either allowing for more variety in the responses, or by allowing the user to advance to the next activity regardless of whether the response they provided was correct.
Replies
11
Boosts
2
Views
3.9k
Activity
Jul ’24
Swift Playgrounds warning when containing visionOS conditional code.
I'm getting the following error when previewing my Swift Playground package: Unrecognized platform name 'xrOS'; did you mean 'iOS'? Anyone know how to silence this? I don't have xrOS anywhere in my code so I'm guessing this is something with Swift Playgrounds or with the compiler.
Replies
2
Boosts
0
Views
1.5k
Activity
Jun ’24
"Cannot find (...) in scope"
Hello! I am a new to programming and developing and I have a question: I tried using Xcode and copied my code from Playgrounds into my Xcode Project. But now it says 50 times "Cannot find (...) in scope." In Playgrounds my code worked. What am I doing wrong? Thank you very much!
Replies
4
Boosts
1
Views
9.6k
Activity
Jun ’24
beta version?
is there a beta version of Swift Playgrounds that supports the latest iPadOS 18 SDK, or do i have to use XCode on Mac?
Replies
1
Boosts
2
Views
1.1k
Activity
Jun ’24
SWIFT Playgrounds crashes on Mac and iPad
Hi, I want to learn SWIFT and started to use SWIFT Playgrounds 4.4 on iPad and MacBook Air. Unfortunately SWIFT Playgrounds unexpectedly crashes every 2nd to 3rd chapter I work on. I am currently trying to finish "Los gehts mit Code" and "Programmieren lernen 1". Is the app really so buggy, that it randomly crashes on executing the starting chapters ?
Replies
9
Boosts
1
Views
2.3k
Activity
Jun ’24
Xcode 14.2 - No output on the right side
My Mac is older one. I just started to learn Swift. I want to practice it. So I downloaded Xcode 14.2 for MacOS 12.7.4 (21H1123) On tutorials, it is showing live result. But for me nothing is happening. It is blank. How do I enable it?
Replies
1
Boosts
0
Views
802
Activity
May ’24
Swift Playgrounds 4.1 keeps crashing when rerunning code
Try to learn some Swift coding but Playgrounds keeps crashing. I run Playgrounds 4.1 on latest Monterey 12.7.5, from a MacBook Air dated back 2017. Part of the error log says: Thread 9 Crashed:: Dispatch queue: com.apple.UIKit._UIViewServiceInterfaceConnectionRequest com.apple.PlaygroundsMac.ExecutionExtension The error can be reproduced by re-running the code; Everything goes well when the code was run at first time, but is doomed to fail at second run. Any help?
Replies
1
Boosts
1
Views
1.1k
Activity
May ’24
Playgrounds
I've noticed Playgrounds crashing a lot lately, both on iPad and Mac. I have many Macs, Intel & M1, and 2 iPads, 7th Gen and 10.5" Pro. It's noticeably sluggish at the best of times progressively getting worse the last few updates, but worse than that it is hard crashing, losing data in the process. Anyone else seeing this? Not the end of the world, I'm a dev and use Xcode for anything substantial but I like to use Playgrounds on the iPad sometimes when I want to pop a quick idea down. I also plan to start creating playgrounds to help kids get into programming, so hoping this useful app isn't being neglected.
Replies
2
Boosts
0
Views
1.1k
Activity
Apr ’24
Update Goal Instruction in Swift-UI Playgrounds Learn to Code 2
In Swift-UI Playgrounds Learn to Code 2 under the Chapter "Variables" and the exercise "Checking for Equal Values", there is no instruction to use the predefined variable numberOfSwitches in the goal instruction.
Replies
0
Boosts
0
Views
942
Activity
Apr ’24
How do you include custom symbol resources in a package?
I am trying to include custom symbol resources in a swift package for use in other projects. I have read the documentation here: https://developer.apple.com/documentation/xcode/bundling-resources-with-a-swift-package However there is no example code and I have created a very simple project to try and get this working but it does not. .target( name: "TestLibrary", resources: [.process("Resources/Media.xcassets")] ), This is in the Package.swift file and the path relative to the Package.swift file is Sources/TestLibrary/Resources/Media.xcassets. There's a GitHub project with an example custom SF Symbol SVG (but this may not be available in the future): https://github.com/kudit/TestLibrary Including this as a package in a blank Swift Playgrounds App project and just importing the TestLibrary and including TestImageView() in the ContentView technically works (it shows the system full star image, but none of the ways of rendering the test symbol as recommended works. It does work for a few of the options in the #Preview when viewing the project in Xcode. Anyone have any suggestions or know how to get the resources to be accessible from outside the module? I have tried both the .copy( option as well as the .process( option and neither seem to work.
Replies
1
Boosts
0
Views
1.3k
Activity
Apr ’24
Documentation
Does anyone know of any documentation for the various directives in the guidebook? Things like @GuideBook, @Guide, @Task, @SuccessMessage, etc. Thanks, David
Replies
1
Boosts
0
Views
1.2k
Activity
Mar ’24
Playground can not create newbook / download sample playground after iCloud folder deletion, but it crashes
Hello All, I happen to remove "Playgrounds" folder from my iCloud drive, and afterwards Playground is no longer functioning but repeatedly crashes. It was okey before deletion, but now any operation to create or download playground then Playground App crashes all the time. Issue not resolved even creating same name folder by manual, Issue not resolved even re-install Playground - folder in iCloud will not created. I guess I need to fully uninstall PlayGround completely, then start from scratch to let Playground App to hold init step to generate required folder in iCloud, but not sure how to do it. Please give kind help if anyone knows about this issue, or if anyone knows complete deletion step of Playground. Best wishes, tons of thanks in advance. Best Regards, Issey Hamada
Replies
2
Boosts
0
Views
967
Activity
Mar ’24
The output of the below code is different from what is anticipated
I was expecting all of the code to run in main thread, but both task and async function is working in backfround thread. Any explanations?
Replies
2
Boosts
0
Views
1.3k
Activity
Mar ’24
NavigationPath(_items: SwiftUI.NavigationPath.(unknown context at
I tried to use navigationstack, and it works. but couldn't print the path, and with the message: " NavigationPath(_items: SwiftUI.NavigationPath.(unknown context at $7ff84b690a28).Representation.eager([SwiftUI.(unknown context at $7ff84b6907f0).CodableItemBox<Swift.String>]), subsequentItems: [], iterationIndex: 0). " `import SwiftUI var toDos: [String] = [ "list1", "list2", "list3" ] struct ContentView: View { @State private var path = NavigationPath() var body: some View { NavigationStack(path: $path) { List { ForEach(toDos, id:\.self) { toDo in Button(action: { path.append(toDo) print(path) }, label: { Text("go to " + toDo) }) } } .navigationDestination(for: String.self) { toDo in Text("page for " + toDo) } } } } #Preview { ContentView() }` I tried navigationlink and simulator still works fine, but cannot print anything of path
Replies
0
Boosts
0
Views
935
Activity
Mar ’24
App Download Size Nag Email - "Universal" device type
Whenever we submit a new release to the App Store we get a nag email from Apple that states, "The app binary listed below was 199.2 MB when you submitted it, but will be 223.9 MB once processed for the App Store. This exceeds the cellular network download size limit and may require your app to be downloaded over Wi-Fi." However, when I download the app from the App Store and have the Settings set to "Alway Ask" on my phone the alert shows 129 MB, which is matches up closely with what we see in the TestFlight metadata for all device types except "Universal". What is "Universal" device type in these days of thinning? And why is Apple apparently using that number to generate the nag email?
Replies
0
Boosts
1
Views
954
Activity
Mar ’24