swift properties

class PropertiesClass1 {
	var a = "Stringa"
	init() {
		print("初始化")
	}


}

class PropertiesClass2 {
	var id  = 0
	//lazy 懒加载,只有使用的时候才触发
	lazy var properties1 = PropertiesClass1()

	//初始化必须全部初始化所有属性,或者为Options
	var name: String? 

	//geter seter
	var qq: String {
		//geter seter 里面不能使用自己属性,否则会死循环
		get {
			return self.name!
		}
		set {
			self.name = newValue
		}
	}
	//只读属性
	var height: Int {
		return 180
	}

	var address: String = "xxx" {
		willSet {
			print(" 新值\(newValue)")
		}

		didSet {
			print("旧值 \(oldValue)")
		}
	}

	
}

var properties2 = PropertiesClass2()

print(properties2.properties1)


properties2.qq = "65683264"
print(properties2.qq)

print(properties2.height)
// properties2.height = 2

properties2.address = "ca"

  

posted @ 2016-02-24 15:51  _Miss_once  阅读(137)  评论(0编辑  收藏  举报