Swift Playgrounds

RSS for tag

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

Swift Playgrounds Documentation

Post

Replies

Boosts

Views

Activity

Swift Playground: second episode uses unreferenced command
I am using Swift Playground to teach "coding" to my nephew. One of the strict requirements I am trying to explain him is: when you are required to solve a problem, you need to use only the instructions/harward/etc you have available. In the first episode of "Get started with code" -> "Commands" -> "Issuing commands", you are presented with two commands moveForward() and collectGem(). In the second episode "Toggle a Switch" you are introduced to a new command "toggleSwitch()". Up to this point, the learner was introduced to three commands: moveForward(), collectGem(), toggleSwitch(). However, in order to solve the puzzle in the second episode, you need also to use another command: turnLeft(), that has not been referenced. It is clear that looking for unknown commands is part of learning to code, but this occurs too early in the playground. Please consider also that some non-English young learners have no idea on how to write "turn left", so they cannot even type the first letters and hope in the auto-completion of the commands. This has not been well thought by the designers of the playground.
1
0
396
Jan ’24
App Playground deployment target?
Hi! I'm preparing to apply for the Swift Student Challenge and had a question. In the terms and conditions, it says "Your app playground must be built with and run on Swift Playgrounds 4.4 or later (requires iPadOS 16 or macOS 13.5) or Xcode 15 on macOS 13.5 or later. You may incorporate the use of Apple Pencil." Does this mean that my app must run on iPadOS 16 or macOS 13.5, or can it run on iPadOS 17 or macOS 14 or later as long as it runs on Playgrounds 4.4? In other words, what should I set my Deployment Target to? Thanks for your help in advance 😜
1
0
466
Jan ’24
Show Table in SwiftUI Playground
I am trying to generate a simple playground to display Table structure with several TableColumns. Basically, generated a new blank playground; add import statements for SwiftUI and PlayGround support; add structure for content view and a statement for invoking that view as: `PlaygroundPage.current.setLiveView(ContentView()) In general, all of the view components work as expected EXCEPT for the table structure which does not display anything. Its basic structure is: Table(rows, selection: $selRow) { TableColumn("ID") {Text(String($0.id))} TableColumn("Name", value: \.nt) } where "rows" is an array of the structure TRow: struct TRow : Identifiable { var id:Int var num:Int var nt:String } Is there some special trick to allowing a SwiftUI Table to be displayed in Playground?
1
0
376
Dec ’23
Not able to run Playground Basics from Swift Explorations
Hi, I wanted to learn basics on developing in iOS and started with Swift Explorations. I have installed Xcode 15.0.1 and running it on Ventura 13.5.1. When I execute the Playgroung Basics.playground file, I get an error message saying "Failed to attach to stub for playground execution". Any clue as to why that might be? I am able to create my own playground and execute it properly. I searched around but could not find anything on the topic (other than disablig Rosetta which is not an option as far I can tell in my case; don't see that checkbox under Get Info). Any pointer would be welcome. Cheers, Piloo
2
0
368
Dec ’23
Playground issue
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) } } }
2
0
544
Nov ’23
Swift Playgrounds beta with support for iOS 17 and macOS 14 expired!
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.
3
3
804
Sep ’23
XCode 15 bug - Playground cannot find file inside Resources
I have the simplest Playground to display image. I have images inside Resources. Somewhat it does not work and I am really confused. I am using macOS XCode. I think on iPad Swift Playground this might work. import SwiftUI import PlaygroundSupport struct ContentView: View { var body: some View { Image("image1") .resizable() .frame(width: 512, height: 512) } } let hostingController = UIHostingController(rootView: ContentView()) PlaygroundPage.current.liveView = hostingController
2
1
650
Sep ’23
Any approaches to Swift Playgrounds on macOS Monterey?
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!
1
0
586
Sep ’23
Not able to reference classes/structs in Swift playground sources
I have to admit that this is strange for me. Though I have been using playgrounds for years, but I only write small pieces of code to test simple ideas, and I never used another source file. Today I want to add a new struct in Sources folder. To my surprise, I am not able to reference the struct in the main playground file. Sources/testlets.swift: struct Dummy { var name: String } MyPlayground: var box = Dummy(name: "abc") // error: /.../MyPlayground.playground:22:11 Cannot find 'Dummy' in scope
2
0
575
Aug ’23