- //: Playground - noun: a place where people can play
- class YOU{}
-
- class MyClass {
-
- var arr:Array = ["1","2"]
-
- //延迟实例化
- lazy var obj = YOU()
-
- var prop:String = "hello"
-
- func mymethod(){
- print("no")
- }
-
- //类属性
- static var CP:String = "类型属性"
-
- //类方法
- class func cf(){
-
- }
-
- //属性监视器
- var total:Int = 0{
-
- willSet(newValues){
- print(newValues)
- }
-
- didSet{
- print(oldValue)
- }
- }
-
- }
-
- protocol MyProtocol{
-
- func say(word:String)
-
- }
-
- extension MyClass:MyProtocol{
-
- func test(){
- print(self.prop)
- }
-
- func say(word: String) {
- print(word)
- }
-
- //类只能扩展计算属性,要返回点什么
- var calc:String{
- get{
- return self.prop + ",world"
- }
-
- set{
- self.calc = newValue + "888"
- }
- }
-
-
- // func getInstance(){
- // return self
- // }
-
- // convenience init(){
- //
- // }
-
-
- enum K{
- case A,B,C
- }
-
-
- subscript (outindex:Int)->String{
- return self.arr[outindex]
- }
- }
-
-
- MyClass.CP
-
- MyClass.cf()
-
- var my = MyClass()
-
- my.test()
-
- my.calc = "666"
-
- print(my.calc)
-
- print(my[0])
-
- MyClass.K.A