Questions tagged [swift-playground]

Swift Playgrounds are interactive design environments that evaluate code as you write it. Intermediate results of the code are shown in a right-hand pane.

swift-playground
Filter by
Sorted by
Tagged with
2 votes
1 answer
66 views

What is wrong with this API call parsing JSON data?

This is the current SWIFTUI code I have: import SwiftUI struct Holidays: Decodable { var date: String var localName: String var name: String var countryCode: String } struct ...
0 votes
1 answer
5 views

Cant add package dependencies to xcode playground

I wanted to add a package to my XCode playground but its greyed out: How to find out why I cant anything?
-2 votes
1 answer
1k views

How to use `SELF` in swift playground?

How to reference Swift Playground itself? I am trying to use NSNotificationCenter to observe some variable, but i do not know how to implement it on Playground. Here is my code. I just want to observe ...
-1 votes
0 answers
34 views

Automatically display the Console as a SwiftUI View, or create a View to show a log of messages

I have an app in Swift-Playgrounds on my iPad, but I'd like to display a log of text lines in the lower half of the screen, just like the built-in Console. The problem is, I can't see how to show the ...
0 votes
0 answers
44 views

Modifying the background of views built with NavigationStack and Lists in SwitfUI

NavigationtStack, combined with Lists and Sections makes building a native UI very easy in SwiftUI. Looking at Apple's own apps there are certain bits of flair which I am looking to achieve in my own ...
0 votes
1 answer
41 views

How can I save .playground file devloped in Xcode to .swiftpm

How can I save .playground file devloped in Xcode to .swiftpm. It's Apple requirement to submit the app in swftpm format to be eligible for Swift student challenge 2024. I am struggling for more than ...
61 votes
5 answers
27k views

Debug breakpoint in Swift Playground?

I'm trying to add a breakpoint in the line # gutter, but no breakpoint is added when I do this in the playground. Is this possible or is there another way to set breakpoints in the playground?
0 votes
0 answers
39 views

Core ML model class not getting generated in App Playground Xcode

I am trying to use the SqueezeNet coreML model, but it says that model is not part of any target and to add the model to a target to enable the model class generation. I can not add it to a target ...
-2 votes
1 answer
73 views

how to display loop times in playground [closed]

I want to get the loop times info in playground. But it seems to only display the latest result for a loop on the right side. Do I miss anything? Xcode 15.0.1 import Cocoa for i in 1...5{ print(&...
20 votes
2 answers
2k views

Is there a way to set deployment target for a Xcode playground

I've upgraded to MacOS 11 (Big Sur) Beta 4. And Xcode 12 beta 4. I have a Swift playground with Combine publishers: Just([1,2,3]) .setFailureType(to: Error.self) // Make the compiler pick up new ...
0 votes
0 answers
32 views

Is there a way to change images while using a image inside a NavigationLink in SwiftUI?

I'm relatively new to Swift development and I'm encountering an issue with SwiftUI that I haven't been able to solve despite days of research. I am trying to create a view where an image acts as a ...
1 vote
0 answers
47 views

Cannot delete .xcassets content or folder (even in Finder)

I'm participating in this year's Swift Playground Student Challenge by Apple and encountering an issue in Xcode with the .xcassets catalog. I've created some resources and stored them inside resource ...
1 vote
1 answer
106 views

SwiftUI Image is not showing up in Swift Playground on macOS using Xcode 15

I have a Swift Playground in Xcode 15 that has a file structure as follows: |-.swiftpm/ |----Resources/ | |----cat.png | |----plane.png | |----train.png |----MyApp.swift |----ExampleView....
0 votes
0 answers
14 views

How can I create Author Template in Playground 4.4.1

I created a Playground project for Swift Studwent Challenge. (Playgorund 4.4.1). However, I am using Playground version 4.4.1. I could not create the Authr template via Playground application. I'm ...
1 vote
3 answers
116 views

Sink.receive() Does Not Get called After Declaring an Initial Value in Combine Swift

Issue: I am using a Publisher in a code example which I wrote based on the code example here, [https://developer.apple.com/documentation/combine/observableobject][1]. I expect the print statement ...
3 votes
1 answer
272 views

Using Reality Composer Project File in Swift Playgrounds

To my knowledge, Reality Composer Projects files .rcproject are commonly placed in Xcode projects along with all other source files, then the project can simply be referred to by its name: For ...
0 votes
0 answers
51 views

Swift Playground does not find SpriteKit particle file

I'm making a a project that has to use swift playground (.swiftpm); It uses swiftUI for some elements but the main is on a SpriteKit Scene. My problem is that I want to use a particle and it just can'...
4 votes
1 answer
185 views

Why aren't images showing up in Playground using markdown?

The problem is that Im trying to learn the new documentation for swift using markdown but when I try to bring in an image from a URL in playgrounds it just shows the text, while working on a non-...
0 votes
0 answers
34 views

How to design Swift Playgrounds ipad app to control a car over Bluetooth LE

I am unsure on how to even start. I only have swift playgrounds on the ipad (no Mac) I think the app will have 2 sliders, one for the left wheel speed, the other for right wheel speed. On startup (and ...
1 vote
0 answers
114 views

Swift Playgrounds: How to add HDRI in a non AR RealityKit project?

I am creating a RealityKit project on Swift Playgrounds in Xcode, but I am using it in a perhaps less common way. I am using RealityKit but without AR, which is possible by an initializer of ARView. ...
0 votes
1 answer
55 views

Why does my playground liveView look like an iPad instead of an iPhone in Xcode 15.2?

As title. I have few code want to show in the playground liveView. I wish it looks like iPhone, but it's not. How to change the liveView to iPhone simulator in Xcode 15.2. Should I miss some Xcode ...
20 votes
7 answers
22k views

Swift playground - How to convert a string with comma to a string with decimal

I'm new in the Swift world. How can I converting a String with a comma to a String with a decimal? The code work's fine with a dot (.) The problem is when I'm using a comma (,) ... with: var price ...
2 votes
1 answer
746 views

Xcode Playground: How to "use `thread return -x` to return to the state before expression evaluation."

I've typed a very simple error into an Xcode playground: import UIKit var greeting = "Hello, playground" ["foo", "bar"][2] // error The console correctly ...
1 vote
0 answers
59 views

Swift Playground Bundle can't find Compiled CoreML Model (.mlmodelc)

I have been attempting to debug this for over 10 hours... I am working on implementing Apple's MobileNetV2 CoreML model into a Swift Playgrounds. I performed the following steps Compiled CoreML model ...
0 votes
0 answers
29 views

I can't load a 3D Model into my Playgrounds project in Xcode

I'm doing a SceneKit project using Playgrounds in Xcode. However, when I try to load my field model into the scene, it never appears. I did some debugging and I think my function is not being able to ...
0 votes
0 answers
27 views

Copy resources to App Bundle in Swift Playground [duplicate]

I am attempting to load a USDZ file into a QuickLook view from within a Swift Playground. This USDZ file is in the root of my playground. Unfortunately, my project needs to be a playground so I can't ...
0 votes
2 answers
746 views

Build failed because the Mach-O file couldn’t be generated

I am using Swift Playgrounds on iPad, and every time I try to start my app, it just says “Build failed because the Mach-O file couldn’t be generated.” I have no idea what this means. image I tried ...
0 votes
1 answer
58 views

The behavior of Task seems to differ in Playground environments

In an actual app project, when running the following code, the print statements occur in the order of 1->3->2: var body: some View { Text .onAppear { print("1") ...
64 votes
7 answers
36k views

Xcode: Any way to refresh/re-run the playground?

The Playground in Xcode automatically updates as you type, but I can't figure out how to get the Playground to "re-compile". In many cases this wouldn't matter, but if you're writing code that ...
1 vote
0 answers
238 views

Does SwiftData work in the Xcode Swift Playground? (Xc 15.1)

I'd like to experiment with SwiftData in the Xcode Swift Playground. Some low-level business with lldb prevents me from proceeding. I've set it up like this: // Xcode 15.1 Playground, iOS idiom. ...
3 votes
1 answer
187 views

Xcode playground keep showing progress icon

When I manually run the code, everything seems okay but I don't know why that progressing icon(?) does not disappear. I waited more than 10 minutes. My computer is MacBook Air (M2) I don't know what ...
2 votes
1 answer
138 views

Code in Swift Playground not showing data inside Array

Does anyone know the legit first setting for learning code in Xcode? The data on the right side not showing inside an Array but only the type data inside it. Currently learning it, usually I do code ...
0 votes
0 answers
6 views

Swift Playgrounds on MacOS - Contacts access is promoted, but has no effect

If you follow the examples for permitting your playground Contacts access, it works in Playgrounds/iPadOS, but not on Playgrounds/macOS The prompt appears, and no error is returned, but System ...
1 vote
1 answer
52 views

Is there a way to ignore warnings in dependent packages? Is there a way to #if an os that the compiler doesn't know about?

I am using Swift Playgrounds to do App Development. One of my dependencies has some code like this: #if os(visionOS) That causes my app to have a warning due to Swift Playgrounds not being updated ...
0 votes
0 answers
53 views

SwiftUI Playground Build Schemes

(Xcode 15) When creating a new SwiftUI playground I am getting a warning that says "Skipping duplicate build file in Compile Sources Build Phase ..." I went to SwiftUI Playground > Edit ...
0 votes
1 answer
61 views

Double quotes in HTML in Swift Playgrounds WKWebView?

How do I use HTML that has double quotes("") in a Swift Playgrounds(iPad) WKWebView? I tried to do it this way using \ before the quotes: Note, this was done in a playground not a app. ...
-1 votes
1 answer
106 views

Keep local variable inside a function or not in swift to reduce execution time and memory?

I am working on a project, where we are following a proper code guideline. But recently I stumbled upon a problem whose solution is not in my guideline. The problem is simple. I have two functions one ...
38 votes
7 answers
31k views

Making my function calculate average of array Swift

I want my function to calculate the average of my Double type array. The array is called "votes". For now, I have 10 numbers. When I call the average function to get the average of the array votes, ...
-1 votes
1 answer
107 views

What could cause different output for the same code?

Why does this piece of code produce different output when run in Xcode and Swift Playground? for i in 0...10 { DispatchQueue.global().async { DispatchQueue.global().sync { ...
1 vote
1 answer
34 views

Objective-C class properties not viewable on Swift playground

Question about Objective-C and Swift interoperability. I have some Objective-C headers and implementation files which I am using in a Swift playground for a bridging project. However the Playground ...
0 votes
0 answers
30 views

Swift Playgrounds for iPad - GameCenter Entitlement

The GameCenter entitlement isn’t present in the list of capabilities for iPad playgrounds. Does anyone know if it is possible to add it programmatically? Has anyone had success in doing so, if so, ...
0 votes
2 answers
42 views

Strange behavior with split(separator: )

Why this line of code works in Xcode playground but not in actual Xcode project? let first = string.split(separator: "").sorted().joined() Error: Cannot convert value of type 'String' to ...
6 votes
1 answer
342 views

Pinch Gesture in Swift Playground?

Initially I read you couldn't experiment with touches or gestures in a playground. Then I found that touchesMoved or a tap gesture would react. However, I now am testing a UIPinchGestureRecognizer. ...
1 vote
1 answer
169 views

Swift Playgrounds: Unable to Resolve Package ‘Graphics’ and ‘unzip’ Executable Not Found Error

When I import a package in Swift Playgrounds on my iPad, I receive the following error: This package interactions with libgit2, and it don’t have any release in the origin repository, so I find a ...
-1 votes
1 answer
48 views

In macOS Swift Playgrounds can I draw simple pixel graphics like lines and circles?

Old programmer here teaching myself a bit of macOS and iOS programming. I thought the Swift Playgrounds app might be a way to experiment with some simple pixel drawing code. But Googling and browsing ...
1 vote
1 answer
103 views

Cannot import XCTest in Swift Playgrounds 4.3.1

I'm working in Swift Playgrounds for Mac, v4.3.1. There are a number of tutorials on the web (example) that show using XCTest in XCode Playgrounds. But when I try to import it, I get No such module '...
5 votes
0 answers
1k views

Xcode preview and console too slow or not working

I had just recently downloaded xcode and everytime I write code and come to an error, I would fix the error but the console and preview do not update. It down not change the error live will not rerun ...
2 votes
1 answer
632 views

Is it possible to add a package from a private GitHub repo to an app in Swift Playgrounds for iPad?

I'm creating an app in Swift Playgrounds for iPad and can easily add Swift Packages from public GitHub repositories this way. But how can I add a package from my private repo? I've seen answers ...
6 votes
0 answers
811 views

Why I can't import UIKit in .swift file in sources folder at swift playgrounds?

So I want to make a swift file in the sources folder that imports UIKit, but it says that no such module 'UIKit', why is it like that? Can someone help?
4 votes
2 answers
4k views

'Task' cannot be constructed because it has no accessible initializers

I'm trying new Swift 5.5 await async features and I get that compilation error when I try this in a Playground: let task1 = Task { // ... } 'Task' cannot be constructed because it has no ...

1
2 3 4 5
27