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
2 answers

Incomprehensible errors in Swift

This works: func averageOf(numbers: Int...) -> Float { var sum = 0 for number in numbers { sum += number } return Float(sum) / Float(numbers.count) } averageOf() // (not a number) averageOf(42, 597, 12) // (217.0) But this…
0
votes
2 answers

Playground(Swift) Excecution was interrupted issue

Same piece of code can't run on playground but can in the xcode project. There is error"Excuetion was interrupted.reason:EXC_BAD_INSTRUCTION...." Here is the detail snapshot Question here is to figure out why this issue happen ? Why exist in…
Forrest
  • 122,703
  • 20
  • 73
  • 107
0
votes
2 answers

learning swift by GuidedTour

in this example of GuidedTour of Swift by https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/ var optionalString: String? = "Hello" optionalString == nil var optionalName: String? = "John Appleseed" …
user4441450
0
votes
1 answer

How can I create a Swift playground like GuidedTour.playground

GuidedTour Playground contains both interactive and non-interactive elements and nicely formatted text. The text seems to be locked and can't be edited. I found it as an excellent learning tool. Is it possible to edit contents of it or create…
Janusz Chudzynski
  • 2,700
  • 3
  • 33
  • 46
0
votes
3 answers

Modifying content of immutable array in Swift does not work

Silly beginner Swift question: I am expecting the following 3 lines of code to work in the playground: let items = ["Apple", "Orange", "Pear"] items[1] = "Banana" // error here items Now the error error: '@lvalue $T5' is not identical to…
Misha Birman
  • 90
  • 1
  • 7
0
votes
1 answer

Create NSDate from "2015-01-17T20:00Z" in iOS Swift Project

I'm working with some JSON data that returns a dateTime in this format: "2015-01-17T20:00Z", when I attempt to turn this into an NSDate object, I'm always left with nil. I've read through several of the tutorials and answers here on SO, Apple's…
Kyle
  • 14,036
  • 11
  • 46
  • 61
0
votes
1 answer

Performance problems while pushing pixels with NSRectFill in Swift

This is a Swift Playground that shows an image of the Lorenz Attractor. I have three questions. I will consider this question answered if only the first question gets answered. It's not that fast to begin with but after about 8000-9000 iterations…
Jonas Elfström
  • 30,834
  • 6
  • 70
  • 106
0
votes
2 answers

JSON Complex Arrays in Swift

IS there a way to achieve this in Swift? var z = [ //Error 1 { "Name":{ //Error 2 "First":"Tika", "Last":"Pahadi" }, "City":"Berlin", "Country":"Germany" } ] var c:String =…
tika
  • 7,135
  • 3
  • 51
  • 82
0
votes
1 answer

Xcode playground platform issue

Using Xcode playground I cannot choose platform (iOS or OS X) It stay for me on OS X and even I change on Utilities (View>Utilities>Show File Inspector->Playground Settings->Platform) to iOS I cannot use resources and playground is not…
Mamazur
  • 175
  • 2
  • 8
0
votes
1 answer

User input in Xcode Playground

I'm new to Swift and Xcode. I couldn't figure out how to take user input in Swift playground. I'm trying to write Swift equivalent of the following Python code: def greet(): name = raw_input('What is your name?>') print "Hello ", name Is it…
mgs
  • 2,621
  • 2
  • 19
  • 14
0
votes
2 answers

Loading and registering CGFonts in a Playground

Is there a way to construct a CGFontRef within the context of a Swift Playground? When the following code is run in a playground, 'font' is nil: let path = NSBundle.mainBundle().pathForResource("FiraSans-Medium", ofType: "otf") let provider:…
jbouwman
  • 2,067
  • 2
  • 16
  • 15
0
votes
1 answer

Error with a method that calls another function

I got a mysterious error-message in swift, xcode: The following code has an error at the line with somethingElse(p) that says "Use of unresolved identifier 'somethingElse'". enum symbol: Int { case x = 1 case o = 2 } class player { var…
Jere
  • 1,196
  • 1
  • 9
  • 31
0
votes
1 answer

Xcode Playground crashing with non-swift code

I tried to use Xcode's Playground feature to play around with a bit of new Javascript and Python tricks I started to learn. Unfortunately, whenever I switch the Syntax Coloring (Editor>Syntax Coloring) to a language other then Swift, I type in the…
Ben Avnon
  • 1,681
  • 2
  • 13
  • 13
0
votes
1 answer

Xcode Playground Framework import

While I was working with the Xcode Playground I realized sometimes I have to import Foundation although I already imported Cocoa. Without it functions like sin, cos or lowercaseString refuse to work. As I noticed this morning NSCharacterSet is also…
TalkingCode
  • 13,407
  • 27
  • 102
  • 147
0
votes
2 answers

Swift EXC_BAD_INSTRUCTION when looping to fill an array

let P: UInt32 = 0xB7E15163 let Q: UInt32 = 0x9E3779B9 let r = 20 var S:[UInt32] = Array(count: 2*r+4, repeatedValue: 0) S[0] = P; for i in 1...2*r+3 { S[i] = S[i-1] + Q } The error occurs on the last line of the code where the closing…
Brayden G
  • 93
  • 7