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

Condense 16 if statements into simpler code Swift Playground

I am working in a Swift Playground and I am using multiple toggles to determine if an action in true or false. And from there, the specific combination of them will display a number assigned to each combination. Since I have 4 toggles, I decided to…
EliasFiz
  • 35
  • 7
-2
votes
1 answer

Swift: Protocol and Base Class with same function name

So I was just playing with the protocols and just got confused with the following behaviour. I have a protocol with the function and a base class with the same function name. Now, another class is inheriting from a base class and implementing a…
Hobbit
  • 601
  • 1
  • 9
  • 22
-2
votes
1 answer

Does a subclass inherit convenience initializers from a superclass extension in Swift?

I was trying to make an extension to the Actor type coming from Learn to Code 2 in the Swift Playgounds for iPad as follows: let theWorld = world extension Actor { convenience init(_ x:Int, _ y:Int, facing direction: Direction = .east){ …
lochiwei
  • 1,240
  • 9
  • 16
-2
votes
1 answer

Why does a horizontal line appear in Xcode Playground extension when viewing "Show result"?

I am learning about Swift extensions, and wrote a simple extension to Double in a Playground. Code is below. extension Double { func round(to places: Int) -> Double { let precisionNumber = pow(10, Double(places)) var n…
JMBaker
  • 502
  • 3
  • 7
-2
votes
2 answers

how to write func about comparing boolean in func swift 4

Write a function that returns true if the student has a higher average grade than another student given as a parameter. here my code class Student { var id: Int = 0 var firstName: String = "" var lastName: String = "" init(id: Int,firstName:…
Lorlay
  • 1
  • 1
-2
votes
1 answer

I can't understand the result Why that slash added ? How to remove that?

I have a problem with below extension. That extension will converts Any optional Value to String. Like long, Int, Float and optional string. When I try to convert text like "doesn't contain" optional value it automaticaly added \ in the…
Rajesh Kumar
  • 821
  • 12
  • 20
-2
votes
2 answers

Fatal error: attempt to evaluate editor placeholder: file MyPlayground.playground,

Hello before my xcode wasn't showing anything on the sidebar or in the result area suddenly it started showing and i wrote a small piece of code and getting this error "Fatal error: attempt to evaluate editor placeholder: file…
omi
  • 17
  • 7
-2
votes
1 answer

Swift Playground in Xcode - TapGestureRecognizer to UILabel not working

I am creating a Swift Playground in Xcode and I have a problem with putting a TapGestureRecognizer to an UILabel... class MyViewController : UIViewController { override func loadView() { func tapped() { print("The label was…
-2
votes
1 answer

Calling functions without parenthesis?? [Swift Playground]

Swift provided the code below. How's it possible to call the squishEm function without parenthesis? Isn't that the syntax difference between a function and property? func squishEm() { // Iterate over graphics and squish each one. for graphic in…
BBB
  • 43
  • 7
-2
votes
1 answer

Issue with using variables inside a class function (Swift Playgrounds)

I want to create a function so when a button gets pressed, the content of a variable changes. The function does get called, but I can't use any external variables inside it. This is the code I'm having trouble with: class Responder: NSObject { …
-2
votes
1 answer

Get Swift Playgrounds back? iOS 10 GM Warning

I just updated to the final release of iOS 10.0.1 on iPad Pro 12.9 inch Swift Playgrounds is gone, and it's not in the App Store. I've lost all my Playgrounds, I presume. No great loss. But how do I get Swift Playgrounds back? and... how do I warn…
SKOOP
  • 364
  • 2
  • 14
-2
votes
1 answer

How to use `SELF` in swift playground?

How to reference Swift Playground itself? I am trying to use NSNotificationCenter to observe some variable, but i do not know how to implement it on Playground. Here is my code, actually i just want to observe the timeout variable, but without the…
unknowncoder
  • 132
  • 1
  • 10
-2
votes
1 answer

How to call webAPI?I had created my SIGNUP page but i don't known how to call webapi in button click event

I had created my SIGNUP page but i don't known how to call webapi in button click event IOS SWIFT.**enter code here**
Honestraj19
  • 321
  • 1
  • 3
  • 8
-2
votes
1 answer

Using functions in swift classes

I have been trying to write a code to apply a filter for an image in swift. I am trying out the following code in the playground. It keeps failing for some reason, and I believe it is because I messed up somewhere in the variable referencing for…
Quicksillver
  • 197
  • 4
  • 17
-2
votes
3 answers

Make "int" and "float" work in swift playground

so i am just starting to teach myself a bit ios and am an absolute amateur (please dont be too harsh and forgive questions, of which to you the answers might be obvious). so i wanted to get this following code to work: var int bildBreite; var float…
Gordon
  • 147
  • 2
  • 14