mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-11-27 04:44:08 +03:00
Update swift to beta3
Updated to beta3, new array declaration style,".." and a few other modifications.
This commit is contained in:
parent
06087523c5
commit
ba855b1664
@ -31,7 +31,7 @@ optionalString = nil
|
|||||||
// Array
|
// Array
|
||||||
var shoppingList = ["catfish", "water", "lemons"]
|
var shoppingList = ["catfish", "water", "lemons"]
|
||||||
shoppingList[1] = "bottle of water"
|
shoppingList[1] = "bottle of water"
|
||||||
let emptyArray = String[]()
|
let emptyArray = [String]()
|
||||||
|
|
||||||
// Dictionary
|
// Dictionary
|
||||||
var occupations = [
|
var occupations = [
|
||||||
@ -65,7 +65,7 @@ for (key, value) in dict {
|
|||||||
for i in -1...1 { // [-1, 0, 1]
|
for i in -1...1 { // [-1, 0, 1]
|
||||||
println(i)
|
println(i)
|
||||||
}
|
}
|
||||||
// use .. to exclude the last number
|
// use ..< to exclude the last number
|
||||||
|
|
||||||
// while loop
|
// while loop
|
||||||
var i = 1
|
var i = 1
|
||||||
@ -127,6 +127,7 @@ increment(7)
|
|||||||
//
|
//
|
||||||
// Closures
|
// Closures
|
||||||
//
|
//
|
||||||
|
var numbers = [1, 2, 6]
|
||||||
|
|
||||||
// Functions are special case closures ({})
|
// Functions are special case closures ({})
|
||||||
|
|
||||||
@ -140,8 +141,10 @@ numbers.map({
|
|||||||
})
|
})
|
||||||
|
|
||||||
// When the type is known, like above, we can do this
|
// When the type is known, like above, we can do this
|
||||||
var numbers = [1, 2, 6]
|
|
||||||
numbers = numbers.map({ number in 3 * number })
|
numbers = numbers.map({ number in 3 * number })
|
||||||
|
//Or even this
|
||||||
|
//numbers = numbers.map({ $0 * 3 })
|
||||||
|
|
||||||
print(numbers) // [3, 6, 18]
|
print(numbers) // [3, 6, 18]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user