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

Xcode Playground bugging out after Apple recommended software updates

I recently allowed two Apple recommended updates for my MacBook Pro. One was a security update and I can't remember what the other was. I'm currently running MacOS High Sierra Version 10.13.6. Since the updates, I can't get Xcode Playgrounds to stay…
user9470831
-1
votes
1 answer

How to initialize Main storyboard from playground

I'm using the following simple code to initialize a storyboard inside playground: let storyboard = UIStoryboard(name: "Main", bundle: nil) let controller =…
sger
  • 719
  • 2
  • 12
  • 26
-1
votes
1 answer

Rotating character Swift Playgrounds

I do not know what I did wrong in this code: func findDegree() -> Double { let xValue = directionstick.center.x - 35 let yValue = directionstick.center.y + 20 let newX = xValue*xValue let newY = yValue*yValue let hypo =…
John Song
  • 3
  • 3
-1
votes
1 answer

Programmatically using constraints in a UITableViewCell subview

I am trying to experiment with constraints in Swift Playground, and going crazy. I have a small class CLListTableViewCell: UITableViewCell with a UILabel in it: let nameLabel: UILabel = { let label = UILabel() label.text = "Here is a great…
-1
votes
1 answer

XCode 9.3 missing timeline slider

I installed Xcode 9.3 but I can't enable the playground Timeline slider. I know it is disabled by default; however, the option to enable it under the render documentation box in playground settings does not appear.
-1
votes
3 answers

Writing to CSV won't put text in columns

I'm trying to create a CSV file with some text in it using playgrounds. This is the code: // The text to save let csvText = "Hello,World,Goodbye!" // The path var document = FileManager.default.urls(for: .documentDirectory, in:…
Hapeki
  • 2,153
  • 1
  • 20
  • 36
-1
votes
1 answer

External APIs/SDKs in WWDC submissions

I've been working on my Swift Playgrounds entry for WWDC 2018, and I've been wondering, is there a rule against using external APIs/SDKs? I've been trying to import music into the playground through some kind of MPMediaPicker, but that hasn't been…
Dowland Aiello
  • 440
  • 8
  • 18
-1
votes
1 answer

How to wait for user to click UILabel?

I want to make a while loop wait until a user clicks on a UILabel in a Swift Playground on Xcode. How can I do this? Here's my loop func gameLoop() { while(score >= 0) { let n = arc4random_uniform(3) if(n == 0) { …
Jordan Baron
  • 165
  • 1
  • 15
-1
votes
1 answer

How to save a video to a URL in Swift Playgrounds

I'm trying to instantiate a PHLivePhoto but whenever I try to save the video that constitutes the live photo I can't get it to work. Here's a little code snippet I wrote that handles exporting the video: public func exportFilteredVideo(to outputURL:…
Harish
  • 1,374
  • 17
  • 39
-1
votes
1 answer

decode morse code by character swift

I am trying to make a morse code converter in a swift playground. I got the conversion to work, but I need to make the code "speak" with AVFoundation. How can I decode the morse code string to play the short beep for every '.' and the long beep for…
Matt
  • 21
  • 2
-1
votes
2 answers

'init' has been renamed to 'init(describing:)' in XCode8

It's really going crazy, this single simple line doesn't compile, why? I'm using Xcode Version 8.1 (8B62) Here's the api reference for String(format: String, _ arguments: CVarArg...)
Nandin Borjigin
  • 2,094
  • 1
  • 16
  • 37
-1
votes
1 answer

Playground code: AffineTransform and AnchorPoint don't work as I want

I want to shrink a triangle downward as below: But the triangle shrink upward as below: The transform code is below: layer.setAffineTransform(CGAffineTransformMakeScale(1.0, 0.5)) I tried to use anchorPoint but I can't scceed. //: Playground -…
Feel Physics
  • 2,783
  • 4
  • 25
  • 38
-1
votes
6 answers

Sum of Printed For Loop in Swift

For a project, I'm trying to find the sum of the multiples of both 3 and 5 under 10,000 using Swift. Insert NoobJokes. Printing the multiples of both 3 and 5 was fairly easy using a ForLoop, but I'm wondering how I can..."sum" all of the items that…
Nate
  • 3
  • 2
-1
votes
2 answers

Bool in swift - playgrounds

I'm Learning swift using playgrounds. Can I declare a bool and have it be only true or false so I can use it as a condition for a function?
-1
votes
1 answer

Can't append an array in a for in loop with swift?

So I've been playing around with Swift 3 on playground and am just trying to convert some data analysis stuff I wrote in python (as an exercise in language difference, etc.) For some reason my for in loop isn't following through with appending the…
Ezra Goss
  • 124
  • 8