Lesson3

作者: 克罗克达尔 | 来源:发表于2018-11-29 14:55 被阅读3次

如何使用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)
            }
        }
    }

Access Control

访问控制

相关文章

网友评论

      本文标题:Lesson3

      本文链接:https://www.haomeiwen.com/subject/inqfcqtx.html