remov stateIDs

This commit is contained in:
John Estropia
2019-10-12 07:20:09 +09:00
parent 81dfb8e3e5
commit 5af0d17de4
31 changed files with 456 additions and 291 deletions

View File

@@ -116,6 +116,27 @@ open /*abstract*/ class CoreStoreObject: DynamicObject, Hashable {
internal let rawObject: CoreStoreManagedObject?
internal let isMeta: Bool
internal class func metaProperties(includeSuperclasses: Bool) -> [PropertyProtocol] {
func keyPaths(_ allKeyPaths: inout [PropertyProtocol], for dynamicType: CoreStoreObject.Type) {
allKeyPaths.append(contentsOf: dynamicType.meta.propertyProtocolsByName())
guard
includeSuperclasses,
case let superType as CoreStoreObject.Type = (dynamicType as AnyClass).superclass(),
superType != CoreStoreObject.self
else {
return
}
keyPaths(&allKeyPaths, for: superType)
}
var allKeyPaths: [PropertyProtocol] = []
keyPaths(&allKeyPaths, for: self)
return allKeyPaths
}
// MARK: Private
@@ -144,6 +165,22 @@ open /*abstract*/ class CoreStoreObject: DynamicObject, Hashable {
}
}
}
private func propertyProtocolsByName() -> [PropertyProtocol] {
Internals.assert(self.isMeta, "'propertyProtocolsByName()' accessed from non-meta instance of \(Internals.typeName(self))")
let cacheKey = ObjectIdentifier(Self.self)
if let properties = Static.propertiesCache[cacheKey] {
return properties
}
let values: [PropertyProtocol] = Mirror(reflecting: self)
.children
.compactMap({ $0.value as? PropertyProtocol })
Static.propertiesCache[cacheKey] = values
return values
}
}
@@ -187,4 +224,5 @@ fileprivate enum Static {
// MARK: FilePrivate
fileprivate static var metaCache: [ObjectIdentifier: Any] = [:]
fileprivate static var propertiesCache: [ObjectIdentifier: [PropertyProtocol]] = [:]
}