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
236
votes
16 answers

How to iterate for loop in reverse order in swift?

When I use the for loop in Playground, everything worked fine, until I changed the first parameter of for loop to be the highest value. (iterated in descending order) Is this a bug? Did any one else have it? for index in 510..509 { var a =…
RK-
  • 12,099
  • 23
  • 89
  • 155
126
votes
8 answers

Class 'ViewController' has no initializers in swift

Getting the complaint from the compiler when I am doing this class ViewController: UIViewController { var delegate : AppDelegate override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the…
tranvutuan
  • 6,089
  • 8
  • 47
  • 83
125
votes
8 answers

How do I run Asynchronous callbacks in Playground

Many Cocoa and CocoaTouch methods have completion callbacks implemented as blocks in Objective-C and Closures in Swift. However, when trying these out in Playground, the completion is never called. For example: // Playground - noun: a place where…
ikuramedia
  • 6,038
  • 3
  • 28
  • 31
110
votes
9 answers

error: module file's minimum deployment target is ios8.3 v8.3

All attempts to import a dynamic framework in an Xcode playground yield the following error: error: module file's minimum deployment target is ios8.3 v8.3
Vatsal Manot
  • 17,695
  • 9
  • 44
  • 80
102
votes
3 answers

Xcode playgrounds can't access swift files in Sources folder

I just upgraded to Xcode 6.3 and they offered something new to the Playgrounds. If you make a new playgrounds and you open the project navigator, you will see a Sources folder and inside that there is a "SupportCode.swift" file. At the top of that…
DerrickHo328
  • 4,664
  • 7
  • 29
  • 50
99
votes
7 answers

How to print to console using swift playground?

I have been following the Apple Guide for their new language swift, but I don't understand why the bar on the right is only showing "Hello, playground" and not "Hello, world". Can someone explain why the println isn't being printed on the right? //…
Arian Faurtosh
  • 17,987
  • 21
  • 77
  • 115
78
votes
6 answers

How to import own classes from your own project into a Playground

Assume a setup like this: You have an Xcode 6 project, where you've implemented your own classes (say MyView and MyViewController) with both Objective-C and Swift You have added a Playground into your project In the Playground, it's possible to…
Markus Rautopuro
  • 7,997
  • 6
  • 47
  • 60
69
votes
10 answers

How do I make an UIImage/-View with rounded corners CGRect (Swift)

How do I make a UIImageView with rounded corners on a Swift iOS Playground? Inside it needs to be filled with a color.
Thomas
  • 1,468
  • 4
  • 14
  • 20
68
votes
2 answers

How do I "open this chapter as a playground in Xcode"?

I have the Swift book open in iBooks, and see the note “For the best experience, open this chapter as a playground in Xcode.” How is this done?
vonlost
  • 875
  • 1
  • 7
  • 11
65
votes
10 answers

Does swift playground support UIKit?

I tried to create a UILabel in playground but failed. Does playground only support OS X development for now?
bydsky
  • 1,604
  • 2
  • 14
  • 30
64
votes
3 answers

Declarations in extensions cannot override yet error in Swift 4

I have an extension: public extension UIWindow { override public func topMostController()->UIViewController? { ... } } but for my topMostController I get the next error: Declarations in extensions cannot override yet error It works well for…
J. Doe
  • 683
  • 1
  • 5
  • 7
62
votes
7 answers

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 generates or uses random values it can be useful to run…
shim
  • 9,289
  • 12
  • 69
  • 108
62
votes
12 answers

Swift playgrounds with UIImage

I am working with Xcode 6, and I'm trying to recreate the code demoed during session 401 "What's new in Xcode 6". I've added an image to Images.xcassets (called Sample) and within the playground file I'm trying to access this image, as demoed. My…
Ross Gibson
  • 980
  • 1
  • 8
  • 14
61
votes
9 answers

iOS Playground doesn't show UI preview

I've created a simple playground with XCode 7.1 and I've typed this simple code: import UIKit import XCPlayground var str = "Hello, playground" let color = UIColor (red: 1 , green: 1 , blue: 0 , alpha: 0 ) let view = UIView()…
Lubbo
  • 1,030
  • 1
  • 10
  • 18
58
votes
2 answers

How do you prevent Xcode 7 Playgrounds from automatically running?

I'm working on an Xcode 7 Playground that has many things running at once. Whenever I make an edit, it refreshes, restarts what was running and runs through the entire code again. That crashes my playground around every 15 minutes. Is there a way to…
BK15
  • 739
  • 1
  • 6
  • 11
1
2 3
87 88