swift_playground
1.0.0
Swift Playground: explorando e avaliando código Swift em um Playground (copiar e colar)
Estes são os exemplos de:
https://developer.apple.com/library/ios/recipes/xcode_help-source_editor/chapters/ExploringandEvaluatingSwiftCodeinaPlayground.html
Na página acima os exemplos de código estão em imagens, o que é muito chato. Aqui eu os forneço para que você economize tempo copiando e colando:
// Playground - noun: a place where people can play
import UIKit
var str = "Hello, playground"
let triple: Int -> Int = {
(number: Int) in
let result = 3 * number
number
return number
}
triple(3)
let listOfNumbers = 1...5
var sum = 0
for atNum in listOfNumbers {
sum += atNum
}
sum
var j = 2
for var i = 0; i < 5; ++i {
j += j * i
}
j
////////
// let j = 3 // ERROR: Invalid redeclaration of 'j'
////////
let size = (20, 40)
switch size {
case let (width, height) where width == height:
println("square with sides(width)")
width
height
case (1...10, 1...10):
println("")
case let (width, height):
println("rectangle with width (width) and height (height)")
width
height
}
////////
let frame = CGRect(x: 0, y: 0, width: 150 , height: 150)
let customView = UIView(frame: frame) // CheckBox(frame: frame) // Switched to a UIView so the example would work
customView.backgroundColor = UIColor.blueColor()
customView.tintColor = UIColor.orangeColor()
//customView.isChecked = true
////////
j = 2
for var i = 0; i < 5; ++i {
j += j * i
}
j
import XCPlayground
for (_, color) in enumerate([UIColor.orangeColor(), UIColor.greenColor()]) {
customView.backgroundColor = color
XCPShowView("customView", customView)
}
* Swift é uma linguagem proprietária. O Apple's World é uma prisão voluntária.