前端之家收集整理的这篇文章主要介绍了
swift 练习三,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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"
}
}
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
原文链接:https://www.f2er.com/swift/325296.html