标签:写法 sha lse else over 意思 str guard highlight
var num1 : Int = 0 var num2 : Int = 5 /// 1.计算属性 var num3 : Int{ return num1 + num2 } /// 2.闭包属性 private lazy var num4 : Int = { return num1 + num2 }() override func viewDidLoad() { super.viewDidLoad() print(num3) print(num4) }
2.类属性
class Student: NSObject { /// 类属性 static var score : Int = 0 } override func viewDidLoad() { super.viewDidLoad() Student.score = 1 print(Student.score) }
3. 对象属性赋值
class Student: NSObject { var age:Int = 0 ///可选属性: name1 和name2一个意思 var name1:String? var name2:String? = nil } let stu = Student() stu.age = 10 stu.name1 = "1蛋" stu.name2 = "2蛋" print(stu.age) /// 可选属性 解包写法1 if let name = stu.name1{ print(name) } /// 可选属性 解包写法2 guard let name2 = stu.name2 else { return } print(name2)
标签:写法 sha lse else over 意思 str guard highlight
原文地址:https://www.cnblogs.com/qingzZ/p/9952430.html