Branch
Hash :
36a5fa0e
Author :
Date :
2019-06-30T04:19:54
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
<h2>Comments</h2>
<pre><code>// this is a comment
/* this is also a comment,
but written over multiple lines */
</code></pre>
<h2>Numbers</h2>
<pre><code>42
-23
3.14159
0.1
-273.15
1.25e-2
0xC.3p0
1_000_000
1_000_000.000_000_1</code></pre>
<h2>Strings</h2>
<pre><code>let someString = "Some string literal value"
var emptyString = ""
// String interpolation
let multiplier = 3
"\(multiplier) times 2.5 is \(Double(multiplier) * 2.5)"</code></pre>
<h2>Control flow</h2>
<pre><code>for index in 1...5 {
println("\(index) times 5 is \(index * 5)")
}
for _ in 1...power {
answer *= base
}
while square < finalSquare {
// roll the dice
if ++diceRoll == 7 { diceRoll = 1 }
// move by the rolled amount
square += diceRoll
if square < board.count {
// if we're still on the board, move up or down for a snake or a ladder
square += board[square]
}
}
switch someCharacter {
case "a", "e", "i", "o", "u":
println("\(someCharacter) is a vowel")
case "b", "c", "d", "f", "g", "h", "j", "k", "l", "m",
"n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z":
println("\(someCharacter) is a consonant")
default:
println("\(someCharacter) is not a vowel or a consonant")
}
</code></pre>
<h2>Classes and attributes</h2>
<pre><code>class MyViewController: UIViewController {
@IBOutlet weak var button: UIButton!
@IBOutlet var textFields: [UITextField]!
@IBAction func buttonTapped(AnyObject) {
println("button tapped!")
}
}
@IBDesignable
class MyCustomView: UIView {
@IBInspectable var textColor: UIColor
@IBInspectable var iconHeight: CGFloat
/* ... */
}</code></pre>