public class EntityA: NSManagedObject {
@NSManaged public private(set) var identifier: String
@NSManaged public private(set) var name: String
}
public class EntityB: NSManagedObject {
@NSManaged public private(set) var identifier: String
@NSManaged public private(set) var name: String
}
protocol NodeRepresentable {
var children: NSArray { get }
static var childrenKeyPaths: [String] { get }
}
extension NodeRepresentable where Self: NSManagedObject {
var children: NSArray { //swift compiler doesn't see this as KVC complaint
return Self.childrenKeyPaths.flatMap { keyPath in
return self.mutableSetValueForKey(keyPath)
}
}
}
extension EntityA: NodeRepresentable {
static var childrenKeyPaths: [String] {
return ["events", "groups", "races"]
}
var _children: NSArray { //this is KVC complaint
return self.children
}
}
extension EntityB: NodeRepresentable {
static var childrenKeyPaths: [String] {
return ["events", "groups", "markets"]
}
var _children: NSArray { //this is KVC complaint
return self.children
}
}
编译器没有为EntityA和EntityB上的子项找到valueForKey。 协议扩展似乎没有实现KVO投诉属性。我已尝试在协议上声明动态属性,但这并不起作用。
是否有可能避免使用某种语言功能在每个实体上声明计算var?
答案 0 :(得分:0)
Swift属性扩展对Objective-C不可见。
尝试将/pusher/auth
添加到声明中。即@objc