您的位置:首页 > 移动开发 > Swift

iOS.swift protocol使用时碰到的小问题

2015-11-25 10:19 309 查看
swift中,我们在定义protocol的时候,可能存在protocolA,protocolB中的方法名一致等情况。

protocol A{
func content() -> String
}

protocol B{
func content() -> Int
}


那么当我们在遭遇 class Class: A, B{} 的时候,如何去解决调用的到底是哪一个protocol里的方法呢?

class Class: A, B{
func content() -> String{...}
func content() -> Int{...}
}

let subClass = Class()
let str = (instance as A).content()//打印protocolA中的内容
let int = (instance as B).content()//打印protocolB中的内容
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  swift protocol