@fiy-fish
2017-04-08T20:40:33.000000Z
字数 912
阅读 2641
工作日志
//基本写法
for index in 1...5 {
println("\(index) times 5 is \(index * 5)")
}
//如果用不到下标的话可以使用 _ 代替
let base = 3
let power = 10
var answer = 1
for _ in 1...power {
answer *= base
}
//遍历数组
let names = ["Anna", "Alex", "Brian", "Jack"]
for name in names {
println("Hello, \(name)!")
}
//遍历字典
let numberOfLegs = ["spider": 8, "ant": 6, "cat": 4]
for (animalName, legCount) in numberOfLegs {
println("\(animalName)s have \(legCount) legs")
}
//遍历字符串
for character in "Hello" {
println(character)
}
//常规写法 swift 3.0 废弃了这个方法
for var index = 0; index < 3; ++index {
println("index is \(index)")
}
数组构造语句
var shoppingList: [String] = ["Eggs", "Milk"]
// shoppingList 已经被构造并且拥有两个初始项。
集合的map方法和flatMap方法
Swift高阶函数:Map,Filter,Reduce等-Part 1
文章还没有看,简单的了解了下Map 的用法,其他不懂得话可以看上面的文章
push -f 如果上一次的提交已经push了,那么需要加f参数覆盖服务端,不过不建议这么搞
let list = [1,2,3,4,5,6,7,8,9,10]
let sum = list.reduce(0,combine: {$0 + $1})