我在这里做错了什么?一切似乎都很好。功能签名是正确的。我没有理由认为parent
会成为额外的争论。
import CloudKit
import CoreLocation
public enum OrderDirection {
case ascending, descending
}
open class OrderBy {
var key: String = ""
var direction: OrderDirection = .descending
var parent: OrderBy? = nil
open var sortDescriptor: NSSortDescriptor {
return NSSortDescriptor(key: self.key, ascending: self.direction == .ascending)
}
public convenience init(key: String, direction: OrderDirection, parent: OrderBy? = nil) {
self.init()
self.key = key
self.direction = direction
self.parent = parent
}
open func Ascending(_ key: String) -> Ascending {
return Ascending(key, parent: self)
}
open func Descending(_ key: String) -> Descending {
return Descending(key, parent: self)
}
open var sortDescriptors: [NSSortDescriptor] {
return self.parent?.sortDescriptors ?? [] + [self.sortDescriptor]
}
}
open class Ascending: OrderBy {
public convenience required init(key: String, parent: OrderBy? = nil) {
self.init(key: key, direction: .ascending, parent: parent)
}
}
open class Descending: OrderBy {
public convenience required init(key: String, parent: OrderBy? = nil) {
self.init(key: key, direction: .descending, parent: parent)
}
}
编辑:从屏幕截图切换到实际代码。
答案 0 :(得分:1)
看起来该函数正在尝试调用自身,因此它不期望在升序/降序类的init中存在parent
参数。我建议更改函数的名称,以便调试器更清楚您希望使用哪个函数。将第一个字母改为小写就足够了。
如果他们有相同的范围,我认为你不会遇到同样的问题。
答案 1 :(得分:0)
方法名称以小写字母!!!
开头修正:
open func ascending(_ key: String) -> Ascending {
return Ascending(key: key, parent: self)
}
open func descending(_ key: String) -> Descending {
return Descending(key: key, parent: self)
}