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 playgrounds are interactive documents where Swift code is compiled and run live as you type. Results of operations are presented in a step-by-step timeline as they execute, and variables can be logged and inspected at any point. Playgrounds can be created within an existing Xcode project or as standalone bundles that run by themselves.

Playgrounds provide a great opportunity to document functions and library interfaces by showing syntax and live execution against real data sets. For the case of the collection functions, we’ve created the CollectionOperations.playground, which contains a list of these functions, all run against sample data that can be changed live.

Playgrounds allow you to edit the code listings and see the result immediately.

The new playgrounds are especially useful for educators. You can insert rich instructional content with paragraph headings, diagrams, and links to additional material alongside the interactive Swift code.

New features in Xcode 6.3 playgrounds include the following:

  • Inline results display the output of your Swift code within the main editor window. The results area can be resized and configured to show different views of the output.

  • Stylized text is easy to add to your playground by adding special markup to your comments based on the familiar Markdown syntax. Some available styles are headings, bold, italic, lists, bullets, and links to external or bundled resources.

  • The Resources folder bundles images and other content directly within the playground. These resources can be accessed from your Swift code or from the rich comments within the playground. (Note: with Xcode 6.3 beta 2 use Show Package Contents in Finder to drag files into the playground’s Resources folder.)

Apple provides documentation here:

1311 questions
-1
votes
1 answer

Extraneous Argument with Binding in SwiftUI

I was playing with binding in playground using SwiftUI, it's a very simple code struct Car:View { var kar = "" @Binding var startAnimation: Bool = false var body: some View { HStack { Spacer() Text(kar) …
Farhandika
  • 437
  • 1
  • 3
  • 16
-1
votes
1 answer

Anyone know how to make a multiple choice game in swift playgrounds?

I was wondering if anyone knows how to make a multiple choice game in swift playgrounds with SpriteKit? I don't want to move over to UIController because I prefer spritekit, but I can't find any code on how to make one. Any help would be…
-1
votes
1 answer

Swift Playground Compiler Error: The compiler is unable to type-check this expression in reasonable time;

When I was writing code running on SwiftPlayground, I got this compiling error: "The compiler is unable to type-check this expression in reasonable time" public func toPlaygroundValue() -> PlaygroundValue { let dict: [:] = [ "pitch":…
Fred
  • 314
  • 2
  • 7
-1
votes
1 answer

I can't create a empty array property in a class in Swift

I want to create a class in Xcode Swift see this code: class Cards { var roundNumber = 10 var monsters:[ (Id: Int, Name:String, Description: String, Attack_min: Int, Attack_max: Int, Health: Int, VP: Int, Gold:Int)] = [ (Id:…
Ralph Schipper
  • 701
  • 2
  • 12
  • 24
-1
votes
1 answer

How to make a multipage Swift Playground

Is there a way for me to click a button in one playground scene and then transitions to another scene? Preferably using SwiftUI
EliasFiz
  • 35
  • 7
-1
votes
1 answer

Change output of a SwiftUI Toggle

Is there a way to change the output of a SwiftUI Toggle. The default values are True and False but can I change to a pair of numbers e.g. 2 and 0
EliasFiz
  • 35
  • 7
-1
votes
1 answer

how to load an image to the playground

In the playground app, I am trying to upload an image, I google it and many solutions said that I need to put my image to resources. But the case is that in the new playground app, the is no resources folder that's why I couldn't add my image. There…
-1
votes
1 answer

While loop with double conditional and || logical operator in Swift

I have a While Loop with a condition that limits it to repeat only 10 times, every time a cycle is repeated a constant D generates a random number in a range from 0 to 24, if D is 0, I change a variable dIsZero to true and prints the cycle where D…
sebas.varela
  • 1,535
  • 2
  • 10
  • 12
-1
votes
2 answers

Can you write a forEach() closure within a string .append() in Swift 5? Getting error, so far

I am new to Swift and I am trying to experiment with the language to familiarize myself with all the cool functionality. Currently, I am trying to write a forEach closure to append a different string depending on the value of the element in the…
DaOhms
  • 11
  • 1
-1
votes
1 answer

Swift Compiler Error: Cannot convert value of type '()' to specified type 'String'

I am using Swift playgrounds and learning about parameters in Lesson 9 of Intro to Swift. func sing(verb: String, noun: String) { print("\(verb), \(verb), \(verb) your \(noun)") } let line = sing(verb: "Row", noun: "Boat") The last line gives…
-1
votes
1 answer

My code won't work on my IPad / won't work in general

I have been working on some code that uses a button to call a scene. However it won't work on my IPad and I think I may have done a few things wrong, would anyone be willing to tell me how to get it to work. Here is my code: import SpriteKit import…
Oscar Biggins
  • 13
  • 1
  • 8
-1
votes
1 answer

I cannot access to URL instance on the playground(Swift)

Before I start, I want to let you know that I am not a good English speaker. But if you answer me, I will translate the best I can. I couldn't find the answer for "What should I do to access the URL". I just wanted to make a URL instance in…
BDios
  • 1
-1
votes
2 answers

How to properly call another function within a function in swift?

I'm learning an swift and I've written two functions and have tried them on their own they both work well. However when I try to call one function within another one I can't seem to get the desired out-put that I seek. The task at hand is that one…
Kamanda
  • 305
  • 3
  • 4
  • 11
-1
votes
1 answer

How to fix "Extra argument 'at' in call" in swift's playground

I've got a problem with some code. While I was writing function to define variables in a table I had an "Extra argument 'at' in call" error. I was trying many, many things (including rewritting code from Udemy lesson) and sadly it is not working…
Saq
  • 1
-1
votes
1 answer

Can we use Face Tracking on Swift Playgrounds?

So basically the Delegation method func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? aren't called on Swift Playgrounds. I'm using an iPad Pro 11 (with Truedepth frontal-camera). I tried to run the same code on Xcode,…