Swift协议合成

来源:互联网 发布:pdf阅读器有没有mac 编辑:程序博客网 时间:2024/06/05 10:08
import Foundationprotocol A {    func show() -> Void}protocol B {    func eat() -> Void}protocol C:A,B {    func run() -> Void}class One: A{    func show() {        print("A类的show方法")    }}class oneMore: A {    func show() {    print("SSSSS")    }}var o = One()var oMore = oneMore()var arr:[A] = [o,oMore]var ttt = arr[0] as! Oneprint(ttt)class Two: B {    func eat() {        print("吃")    }}class Three: C {    func show() {        print("展示")    }    func eat() {        print("吃")    }    func run() {        print("跑")    }}func test(obj:A&B) -> Void{}var one = One()var two = Two()var three = Three()test(obj: three)
原创粉丝点击