[英]Swift: Extend a class with a where clause, to conform to a protocol
I am trying to extend a specific type of Array, so as to conform to an existing protocol. 我正在尝试扩展特定类型的Array,以符合现有协议。
extension Array where Element == Int : ProtocolX { }
But the compiler complains that 但是编译器抱怨
Closure expression is unused
闭包表达式未使用
How do i go about implementing a protocol for a type with certain criteria? 如何为具有特定条件的类型实现协议?
声明条件一致性时,协议一致性需要放在where
子句之前。
extension Array: ProtocolX where Element == Int { }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.