【发布时间】:2015-09-26 17:10:28
【问题描述】:
我正在尝试为特定类型的元素创建数组扩展。 这是我写的:
(UnElement是一个符合CustomStringConvertible、Equatable、Comparable协议的类)
extension Array where Element : UnElement {
mutating func ajoute(new: UnElement) -> Bool {
if new.pKey == nil {
return false
} else {
if self.contains(new) {
return false
} else {
self.append(new)
return true
}
}
}
}
但contains 方法出现错误:
无法使用
(UnElement)类型的参数列表调用“包含”
当然,append 也一样。
好像没有指定数组元素的类型,不知道为什么。
【问题讨论】: