swift 练习三
发布时间:2020-12-14 01:36:35 所属栏目:百科 来源:网络整理
导读://: 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 = "类
//: 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
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |