ios - 覆盖测试目标中的协议默认实现
问题描述
我的主要目标中有一个协议:
protocol Animatable: UIView {
static var shouldAnimate: Bool { get }
}
和我的主要目标中的默认实现:
extension Animatable {
static var shouldAnimate: Bool { return true }
}
和符合此协议但没有实现的对象.shouldAnimate
:
class MyView: Animatable { }
在我的测试目标中,我想覆盖默认实现,所以我写道:
extension MyView {
static var shouldAnimate: Bool { return false }
}
在我主要目标的代码中的其他地方我写了print(MyView.shouldAnimate)
end 我希望看到输出:
- 如果我只运行主要目标
true
- 如果我运行我的测试
false
但是当在这两种情况下我看到true
并且默认实现总是从这个协议中触发?为什么?运行测试目标时不应该用类实现覆盖吗?
解决方案
推荐阅读
- java - 如何让 Saxon XSLT 处理器向 stderr 或 log4j 报告错误?
- sqoop - 无法使用 sqoop 连接 Mysql 路由器
- php - Laragon Xdebug 冻结 PhpStorm
- java - 使用 selenium java 登录应用程序时,如果实际结果与预期结果不匹配,则不会显示错误
- kerberos - Kerberos 服务认证
- python - 根据第一行限制 CSV 列读入数据帧
- angular - 如何将值传递给子组件 Anguar?
- pandas - 用更多条件标记重叠的日期时间范围
- java - 在使用 java 的 json 操作中需要帮助
- android - jetpack compose java.lang.IllegalStateException:开始/结束不平衡