相关疑难解决方法(0)

Swift协议扩展覆盖

我正在尝试Swift协议扩展,我发现这个令人困惑的行为.你能帮助我如何得到我想要的结果吗?

请参阅代码最后4行的注释.(如果需要,可以将其粘贴到XCode7游乐场).谢谢!!

//: Playground - noun: a place where people can play

import UIKit

protocol Color { }
extension Color {  var color : String { return "Default color" } }

protocol RedColor: Color { }
extension RedColor { var color : String { return "Red color" } }


protocol PrintColor {

     func getColor() -> String
}

extension PrintColor where Self: Color {

    func getColor() -> String {

        return color
    }
}


class A: Color, PrintColor { }
class B: …
Run Code Online (Sandbox Code Playgroud)

xcode swift swift2

50
推荐指数
3
解决办法
3万
查看次数

标签 统计

swift ×1

swift2 ×1

xcode ×1