swift - 为什么 Swift 不认为协议采用者属性是一致的?
问题描述
protocol Animal {}
struct Lion: Animal {}
protocol Zoo {
var animals: [Animal] { get }
}
struct BronxZoo: Zoo { // error: Type 'BronxZoo' does not conform to protocol 'Zoo'
var animals: [Lion] = []
}
如果BronxZoo
有一个animals
类型为 的数组Lion
,它符合Animal
,那么为什么不BronxZoo
被认为符合Zoo
?
解决方案
推荐阅读
- redis - Redis占用更多内存
- r - 无边界的 R 序列生成
- jquery - 我想在 wordpress 中悬停时更改 img 的 url
- javascript - 未捕获的 TypeError:非法调用 ajax
- spring-boot - 如何在 Redis 中保存 JWT?
- r - 将一张表与 R 中的多个表连接起来
- python-3.x - 根据另一列的值不同地移动行
- java - 无法通过 twitter 应用程序中的邮递员注册 webhook
- javascript - highcharts 5.0.14 问题与 textOverflow
- wordpress - 当 meta_value 是序列化对象时,如何过滤帖子?