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

Posts under Swift Playgrounds tag

279 Posts
Sort by:
Post not yet marked as solved
0 Replies
193 Views
I am trying to build an app where there is a premium version and a free version. When someone purchases the premium version, I want a new screen to show. How do I do this. Code import SwiftUI struct ContentView: View {     var body: some View {           VStack {     Link(destination: URL(string: "https://www.icloud.com/sharedalbum/#B0tG4Tcsmu6ATjR")!) {                 VStack {                     Image(systemName: "paperplane")                         .font(.largeTitle)                     Text("Click here to get wallpapers!")                         .accentColor(Color.white)                         .background(Color.black)                         }                     }                     }                 }             } Premium Code import Foundation import SwiftUI struct Premium: View {     var body: some View {           VStack {     Link(destination: URL(string: "https://www.icloud.com/sharedalbum/#B0tG6XBubu4jvR9")!) {                 VStack {                     Image(systemName: "plus")                         .font(.largeTitle)                     Text("Click here to get Premium wallpapers!")                         .accentColor(Color.white)                         .background(Color.black)                     }                 }             }         }     }
Posted Last updated
.
Post marked as solved
3 Replies
599 Views
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!
Posted Last updated
.
Post not yet marked as solved
1 Replies
449 Views
Trying out playgrounds for the first time and I noticed something a little odd. In the first lesson when it talks about moving byte to toggle a switch it clearly said that the light turns on when the switch is ”Open” and off when “Closed”. This seems counter intuitive to the way we would normally teach electrical theory. We would use the example of a simple electrical circuit with a light. When the switch is closed the light turns on because the circuit is complete and the light receives power. When the circuit is open there is a break in the circuit and the light can not receive power. Just wonderiong if there was a specfic reason for teaching it this way in playgrounds?
Posted Last updated
.
Post not yet marked as solved
1 Replies
192 Views
I have reached to Learn to Code 2, Chapter: Types, Corner of The World puzzle. however; I have provided a solution and the Playground did not close the puzzle, but the avatar stop moving as it meets the conditions I set!! I searched the internet and found the solution, I copied the solution, the puzzle closed!! but my solution was much shorter than the solution!! I am not sure what is wrong in my code, I have attached my code. `greenPortal.isActive = false orangePortal.isActive = false var numberOfGems = 0 var numberOfSwitchs = 0 func moveAround() {     if isBlockedRight {moveForward()} else {turnRight()         moveForward()              }     if isBlocked {turnLeft()         turnLeft()     } } turnRight() moveForward() for steps in 1...2 {     moveForward()     turnRight()     moveForward()     if isOnClosedSwitch {toggleSwitch(); numberOfSwitchs = numberOfSwitchs + 1}     turnLeft()     turnLeft() } while !isBlocked {     while numberOfSwitchs < 6 {         moveAround()         if isOnGem {collectGem(); numberOfGems = numberOfGems + 1}         if numberOfGems == 6 {greenPortal.isActive = true}         if isOnClosedSwitch {toggleSwitch(); numberOfSwitchs = numberOfSwitchs + 1}         if isOnOpenSwitch {greenPortal.isActive = false}     } }
Posted Last updated
.
Post marked as solved
1 Replies
1.5k Views
Sorry if this has been asked but when I open xcode 13 there is no option to open a playground. There is also no option under along the top. Am I being dumb or just missing something?
Posted Last updated
.
Post marked as solved
1 Replies
243 Views
Hello, I'm trying to make my own app (private) for my home automation which I've made with esp32 microcontroller. at this moment I've developed a small testing app in Xcode with just 1 slider button: LED ON/OFF. I've connected the Led to the esp32. my esp32 creates a web server with the slider button. in Xcode is program the IP url to acces the web server and then control the led with my custom app. QUESTION: Is there a way I can leave out the web server? Custom app controls directly I/O off esp32? when I use the app now, it's kinda slow in reactiontime cause It needs to contact the webserver first.
Posted
by JanssensK.
Last updated
.
Post not yet marked as solved
0 Replies
145 Views
UIVisualEffectContentView.contentView.addSubview appears to be actually trying to add the sub view to the parent UIVisualEffectView in Swift Playgrounds. Code that works fine in an actual iOS app causes Swift Playgrounds to produce error: "Do not add subviews directly to the visual effect view itself, instead add them to the -contentView." Except that is exactly what the code is doing "blur.contentView.addSubview(vib)" So the internal implementation in Swift Playgrounds must be doing something wrong. Again the same code works fine in an iOS app.
Posted Last updated
.
Post marked as solved
4 Replies
2.7k Views
Can I use async in Playground? If so, please show an example. func doStuff() async {   print("here") } doStuff() print("After") //error: 'async' call in a function that does not support concurrency
Posted
by ep4duke.
Last updated
.
Post not yet marked as solved
3 Replies
1.5k Views
I'm in the last task befor the array chapter, with creating my own world.No I'm facing the problem the the platforms do not react on the platformlock.my code is locking that way:world.place(PlatformLock(color: green), facing: west, atColum: 7, row: 6)world.place(Platform(onLevel: 2, controlledBy: PlatformLock(color: green)), atColum3, row: 0)In my code the platform is not moving up when the PlatformLock is getting triggered by the expert.In the previous chapter with existing platforms, I do see they have the color of the PlatformLock. My ones are all the same color and I think that could be the problem, doesn't it?How can I match each Platform with its PlatformLock?Thanks your any idea :-)
Posted
by Tinu0580.
Last updated
.
Post not yet marked as solved
0 Replies
152 Views
I just installed Swift Playgrounds on newly installed Monterey. There is not much else installed (ie, no Xcode). The initial screens of Playgrounds seem to render properly (ie against the blue background). Then when the lesson begins the instruction and coding window appear fine, but the right panel is just a blue background with either nothing at all or a tiny little box at the top of screen that says 0/1. It seems like the animations are not rendering. I have tried to reinstall but same issues. This seems to occur in all the lessons. I have no idea where to even begin troubleshooting this and I have searched the internet and nothing similar seems to be mentioned. Suggestions?
Posted
by Clueless1.
Last updated
.
Post marked as solved
1 Replies
234 Views
So the name on my team name, dev account name and dev forum name is my deadname and I obviously want it gone. I know that I cannot change them normally (which is ridiculous), but is changing any of them an option when migrating from a free dev account to a paid one? So my questions are: 1- I do not have a paid dev account yet. When I get one, will I be able to change one of those names? (or add new ones) 2- Will any of those names that are currently set be publicly seen if I publish an app to the App Store? 3- If I have to create a new account, it is possible to use an account on XCode different from the one on my mac and to use an account on Swift Playgrounds different from the one on my iPad, right? Not really willing to test it myself since if this is not possible I won't pay for this on this account, but will have to create another one. Thanks in advance, Luana
Posted
by lucasmnp.
Last updated
.
Post not yet marked as solved
1 Replies
286 Views
for n in 1...5 {     print(n, terminator: "") } The output is 1 2345 The output is not "12345", as expected. Terminator doesn't work on first iteration inside a for. The error happens randomly and only on first loop. Why? Playgrounds - Version 4.0 (1567.22) on iMac 27'' 5k late 2017
Posted
by Enrico82.
Last updated
.
Post marked as solved
2 Replies
217 Views
Hi. I am currently implementing inter-application communication using DistributedNotificationCenter within swift 5.6 and Xcode Version 13.3.1 (13E500a). So I typed the code below into Playground, but I get the error "Cannot find 'DistributedNotificationCenter' in scope". import Foundation let dnc = DistributedNotificationCenter.default() As this document says, DistributedNotificationCenter is included in the Fundation, so I should be able to use it if I write it that way, but I can't. I would appreciate it if you could tell me how I can use DistributedNotificationCenter Thanks,
Posted Last updated
.
Post not yet marked as solved
0 Replies
483 Views
Xcode 13.2 adds the Swift Playgrounds App project template that works with the upcoming version of Swift Playgrounds. The project template creates an iOS SwiftUI app. SwiftUI has a sprite view to show SpriteKit scenes so I tried adding a new SpriteKit scene to the project. Choosing File > New > File adds a Swift file to the project. The New File Assistant doesn't open. I can add an existing SpriteKit scene to the project. I can view and edit the scene. I can also show the scene in a sprite view so I know this project template supports SpriteKit. Adding an existing SpriteKit scene also adds a Resources folder to the project. When I choose to create a new file from the Resources folder, the New File Assistant opens. But SpriteKit Scene is not one of the file types I can add. How do I add a new SpriteKit scene file to a Swift Playgrounds App project?
Posted
by szymczyk.
Last updated
.
Post marked as solved
1 Replies
176 Views
I I am doing a swift curriculum. I need to find an assistant editor how it is shown on the page. But I can't find it. Please let me know if you know where is it. The first screenshot is how it should look and the second one is what I have now
Posted Last updated
.
Post not yet marked as solved
1 Replies
308 Views
All the files in my app's package add upto 7 MB. But my swiftpm package has a size of 40.7 MB! i dont get how its possible. could you please offer a workaround? Thank you! all my deliverables are done so this sucks :/
Posted Last updated
.
Post not yet marked as solved
0 Replies
149 Views
Since this year they want a .swiftpm file and it can't run on Playgrounds on mac, my submission has to be Swift Playground 4.0.2 for iPad? If I choose Xcode for Mac, will they run on debug or will they try to open it on Playgrounds (and get an error)
Posted Last updated
.
Post not yet marked as solved
1 Replies
170 Views
Hi there! I have a public structure and I called it in my ContentView, but I can't understand where to punt the var/let. I try to put them before "var body: some view" but it gives me these errors.
Posted Last updated
.