【问题标题】:Swift Inherited Protocols and Conformance Checking for the Parent-Protocol父协议的 Swift 继承协议和一致性检查
【发布时间】:2016-07-27 18:17:27
【问题描述】:

我注意到,在 Swift 2.2 中,如果我有一个 protocol A,然后是一个从 A 继承的 protocol B: A,则像这样检查与父协议的一致性会失败:if objectConformingToBWhichInheritsFromA is A 计算为 false,如as? 变体。

我做错了吗?

【问题讨论】:

  • 请向我们展示您的代码
  • 谢谢,原来问题出在其他地方,所以我打算删除这个帖子。
  • 我投票决定将此问题作为题外话结束,因为提出的问题不正确 - 有一个不同的问题导致该人提出此问题

标签: swift protocols


【解决方案1】:

我的游乐场讲述了一个不同的故事

protocol A { }
protocol B: A { }    
class Foo: B { }

let foo = Foo()

foo is A // true
foo is B // true

【讨论】:

  • 哇,谢谢你的回答。结果发现问题出在其他地方,基本上是我失明了,而且项目协议搞混了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-12-31
  • 2014-08-02
  • 1970-01-01
  • 2014-11-09
  • 2017-06-23
  • 1970-01-01
相关资源
最近更新 更多