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

How do I translate Apple API documentation in to real life code?

I find this aspect of learning new things in Swift and Xcode very puzzling. I cannot seem to decipher the actual code I need to write from what I read in the Apple API documentation; In my specific case: the API Reference for 'PlaygroundSupport',…
-1
votes
1 answer

Need help turning on Value history, Xcode 7.3.1 I am using playground, OS X option

I am very new to apple computing, have my first iMac a few months. I am now learning basic code writing. I had found a useful link on you site that turns on view history and displays a graph of the output, just some dots on the screen. In that post…
-1
votes
1 answer

NSURLSession and HTTP

I try use shared session to talk to a http server. In xcode playground, import Foundation var session = NSURLSession.sharedSession() var url = NSURL(string: "http://api.zoomeye.org/user/login") var _data: NSData? var _response: NSURLResponse? var…
attolee
  • 602
  • 1
  • 9
  • 22
-1
votes
2 answers

Swift Syntax Error and init()?

I study swift. I have a question about initializers init(). For example, I want to initialize Int. var number: Int = 20 var number = Int(20) var number = Int.init(20) All expression is same? Second, Why this expression occurs? var check =…
-1
votes
2 answers

First Swift Calculator

I'm learning Swift, and I decided that instead of always copying code from videos, I would try to build something myself. I tried to make a calculator in a Playground to see if I could figure things out, and I came up with this. Is this a good way…
user5597190
-1
votes
1 answer

Swift Playground: NSXMLParser / parse() always returns false

here's my code: public class Payment: NSObject, NSXMLParserDelegate { public var buchungsdatum:NSDate public var valutadatum:NSDate public var betrag:Double public var verwendungszweck:String public var creditorIban:String public var…
-1
votes
3 answers

Consonants and Vowels Swift

I'm new at Swift, could anyone explain to me why I'm keep getting this problem. I'm using Xcode 6.4, but here is my question I hope I cleared it up but I needed my Function to takes in Large String then returns Tuple(numVowels, numConsonants) Count…
Jet Lagg
  • 11
  • 1
  • 3
-1
votes
1 answer

Xcode Playground spaces taken away?

Someone please help!! The fact that these upside down brackets are taking the space between my words are annoying. It looks like this... _var_five_=_5
-1
votes
3 answers

Using NSArray as function parameter

I'm trying to add all elements of one NSArray using the NSNumber in for. Why this code doesn't work in playground example? func sumaEnteros(enteros : NSArray) -> Int { var result = 0 for NSNumber i in enteros{ result +=…
Juan Garcia
  • 843
  • 2
  • 11
  • 34
-1
votes
1 answer

Assigning last array element to a variable in Swift

I have this very simple line of code var dblArray : [Double] = [0.01] var x = dblArray.last println(x * x) The '.last' module returns the last element of the array, which is 0.01. However, based on the playground assistant view, it shows that the…
Adib
  • 1,282
  • 1
  • 16
  • 32
-1
votes
1 answer

Declaring a null statement in swift

I have been working my way around a game in swift and just want to create this statement: if (player1!=null)||(player2!=null) println("You are out of the game") I've already declared a variable for player1 and player2 but how do I go around…
Ben
  • 1
  • 1
-1
votes
1 answer

EXC_I386_INVOP When attempting to copy incremented array value

When I attempt to copy the value of one array at an index +1 to a new array (I attempted to simply do oldArray[index] += 1 but I received a cannot invoke error), I get the code EX_I386_INVOP when it runs twice. Code is included below, any insight…
kidCoder
  • 354
  • 4
  • 17
-1
votes
2 answers

Write Recursive Function to loop through the Collection object in Objective C using Swift language

I have seen people struggling to write an effective recursive function. Almost certainly, people don't get the recursive function working right at the first attempt. This post will help the developers understand what actually needs to be done to…
Deepak Badiger
  • 448
  • 7
  • 18
-2
votes
1 answer

Adding resources to a playground in x-code

I am looking to add an image to the resources folder in my x-code. tutorials have me importing UIKit, but mine defaults to Cocoa, and I can't locate a UIKit. so my coding is failing at UIImageView, and UIImage. Appreciate any guidance on how I…
Paul T
  • 25
  • 5
-2
votes
1 answer

Cannot use mutating member on immutable value: 'parent' is a 'let' constant?

import UIKit import SwiftUI var str = "Hello, playground" struct FianceItem: Identifiable,Codable { public var id: UUID public var type: String public var order: Int32 public var parentID: UUID? public var…
jeryycnlong
  • 131
  • 1
  • 5