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
0
votes
1 answer

Appending an array of images inside for loop - swift

I might be missing something really stupid here but can someone tell me why this isn't working? nothing is getting added to the Array. var goblin = NSImage[]() for (var i = 2; i == 50; i++) { var imageString = "/Users/Neil/Developer/iOS…
Sawyer05
  • 1,604
  • 2
  • 22
  • 37
0
votes
1 answer

How to see Swift variable's address in debugger

I have just started learning swift language by Apple. However I have a doubt, I am not sure how can I see my variable/constant's address in the the debugger. When I use p or po in the debugger, I get the value stored in the variable/constant but I…
Vik Singh
  • 1,563
  • 2
  • 19
  • 36
0
votes
1 answer

Unable to see console output in assistant editor using swift playground

Can any one explain me , why console output is not visible in assistant editor. the bar on the right is only showing "Hello, playground" and the assistant editor is showing blank. // Playground - noun: a place where people can play import UIKit …
Afsara
  • 1,411
  • 3
  • 13
  • 31
0
votes
0 answers

Problems in JSON decoding in Swift (XCode6 beta2)

I made a small demo to request and decode data using a restful API, the API URL is: http://interface.bilibili.tv/playurl?cid=1168445&otype=json This is an API of video URLs, I wrote and ran the code below in playgrounds: import UIKit var url =…
Dicky Tsang
  • 6,135
  • 4
  • 20
  • 18
0
votes
1 answer

Inherited control does not draw

I'm trying to create an own progress bar by subclassing NSProgressIndicator. I wrote the code using a Playground in Xcode 6 and it works fine (the content is being drawn correctly). As soon as I put the class onto the GUI (either as type for a…
Alex
  • 1,221
  • 1
  • 10
  • 19
0
votes
1 answer

Swift NSDate Xcode error - SourceKitService terminated

import Foundation var currentTime = NSDate() println("It is currently", currentTime) This Swift code is very simple and should work, correct? Why am i receiving an error that says "SourceKitService terminated - editor functionality currently…
ejLev
  • 3,061
  • 2
  • 14
  • 17
0
votes
1 answer

Xcode-playground's timeline: white text on white background

I'm playing with playground in Xcode 6 and face an issue with the playground's timeline. Specifically, both the text and background are in white colour which make it unable to see. To see the text, I have to select each line in the panel so that it…
chuonghd
  • 103
  • 1
  • 2
  • 8
0
votes
1 answer

Why does this require an if statement to execute

In the swift book by Apple, there is an enum example. It lets you convert a raw Int to a enum rank. However when I try to remove the if statement, the code gives me Playground execution failed: error: :30:13: error: 'Rank?' does not have a member…
Arian Faurtosh
  • 17,987
  • 21
  • 77
  • 115
0
votes
2 answers

Playground wrong output

I wonder if this is playground bug or it's supposed to work like this: var types = ["0", "1", "2"] // ["0","1","2"] types += "3" // ["0","1","2","3"] types += ["4", "5"] // ["0","1","2","3","4","5"] …
Nat
  • 12,032
  • 9
  • 56
  • 103
-1
votes
1 answer

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 the net are letting me down. Even the chatbots…
hippietrail
  • 15,848
  • 18
  • 99
  • 158
-1
votes
1 answer

Playground Crash: "error: Execution was interrupted, reason: signal SIGKILL." Seeking techniques to simplify code

My project involves creating a table of data with a row for each of the 12 months of the year. The user of the app will define their monthly pay and percentage of pay they want to contribute to his/her 401k. The table shows in which month the user…
-1
votes
1 answer

XCode crashing when allocating 10k objects in Swift Playground

I'm solving a puzzle (Advent of code 2022 day 8) by allocating an object for each digit in the input file. Using the sample input (25 digits) it works fine but doesn't scale to the 99^2 digits in the full input file. Xcode stops responding after…
William
  • 191
  • 8
-1
votes
1 answer

Adding mlModel to Swift playground playgroundbook

I am currently working on my WWDC Student Challenge and struggling with adding MlModel to the playground book. Are there a way to drag and drop like like in the xcode? Thank you
-1
votes
1 answer

How many threads in swift playground?

let conc = DispatchQueue(label: "test", attributes: .concurrent) conc.sync { conc.async { var x = 1 for n in 1...100000 { x += n } print(2) } var x = 1 for n in 1...100000 { x +=…
Nike Kov
  • 12,630
  • 8
  • 75
  • 122
-1
votes
1 answer

Creating texture animation in swift Playground

I want to make a basic game in SpriteKit and want to add some animations into it in swift playgrounds. How can I add texture animations or even add Json file into my Playground