如何使用AutoLayout
Range
代码
for i in stride(from: 0.5, to: 1.5, by: 0.2) {
print(i)
}
输出
0.5
0.7
0.9
1.1
1.3
Tuples
- 一组数据
代码
let x :(name:String,age:Int) = ("hankuke",10)
print("name is \(x.name) ,age is \(x.age)")
输入
name is hankuke ,age is 10
Computed Properties
- 计算属性,和存储属性(Store Properties)不同的是,计算属性并不存在于宿主之上,仅仅在设置的时候改变一些东西或者在取的时候返回一些值。
- 许多时候我们需要一个可以被推到出的属性,而不需要一个存储属性
private var lastChooseIndex : Int?{
get{
var foundIndex:Int?
for index in cards.indices {
if cards[index].isFaceUp {
if foundIndex == nil {
foundIndex = index
}else{
return nil
}
}
}
return foundIndex
}
set{
for index in cards.indices {
cards[index].isFaceUp = (index == newValue)
}
}
}
网友评论