fix issue with early-deallocated CoreStoreObjects

This commit is contained in:
John Estropia
2018-09-18 23:50:14 +09:00
parent 40f458a09c
commit ab40532801
8 changed files with 86 additions and 86 deletions

View File

@@ -138,45 +138,45 @@ public enum ValueContainer<O: CoreStoreObject> {
get {
CoreStore.assert(
self.parentObject != nil,
self.rawObject != nil,
"Attempted to access values from a \(cs_typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types."
)
return withExtendedLifetime(self.parentObject! as! O) { (object: O) in
return withExtendedLifetime(self.rawObject!) { (object) in
CoreStore.assert(
object.rawObject!.isRunningInAllowedQueue() == true,
object.isRunningInAllowedQueue() == true,
"Attempted to access \(cs_typeName(O.self))'s value outside it's designated queue."
)
if let customGetter = self.customGetter {
return customGetter(PartialObject<O>(object.rawObject!))
return customGetter(PartialObject<O>(object))
}
return V.cs_fromQueryableNativeType(
object.rawObject!.value(forKey: self.keyPath)! as! V.QueryableNativeType
object.value(forKey: self.keyPath)! as! V.QueryableNativeType
)!
}
}
set {
CoreStore.assert(
self.parentObject != nil,
self.rawObject != nil,
"Attempted to access values from a \(cs_typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types."
)
return withExtendedLifetime(self.parentObject! as! O) { (object: O) in
return withExtendedLifetime(self.rawObject!) { (object) in
CoreStore.assert(
object.rawObject!.isRunningInAllowedQueue() == true,
object.isRunningInAllowedQueue() == true,
"Attempted to access \(cs_typeName(O.self))'s value outside it's designated queue."
)
CoreStore.assert(
object.rawObject!.isEditableInContext() == true,
object.isEditableInContext() == true,
"Attempted to update a \(cs_typeName(O.self))'s value from outside a transaction."
)
if let customSetter = self.customSetter {
return customSetter(PartialObject<O>(object.rawObject!), newValue)
return customSetter(PartialObject<O>(object), newValue)
}
return object.rawObject!.setValue(
return object.setValue(
newValue.cs_toQueryableNativeType(),
forKey: self.keyPath
)
@@ -200,7 +200,7 @@ public enum ValueContainer<O: CoreStoreObject> {
internal let renamingIdentifier: () -> String?
internal let defaultValue: () -> Any?
internal let affectedByKeyPaths: () -> Set<String>
internal weak var parentObject: CoreStoreObject?
internal var rawObject: CoreStoreManagedObject?
internal private(set) lazy var getter: CoreStoreManagedObject.CustomGetter? = cs_lazy { [unowned self] in
@@ -351,44 +351,44 @@ public enum ValueContainer<O: CoreStoreObject> {
get {
CoreStore.assert(
self.parentObject != nil,
self.rawObject != nil,
"Attempted to access values from a \(cs_typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types."
)
return withExtendedLifetime(self.parentObject! as! O) { (object: O) in
return withExtendedLifetime(self.rawObject!) { (object) in
CoreStore.assert(
object.rawObject!.isRunningInAllowedQueue() == true,
object.isRunningInAllowedQueue() == true,
"Attempted to access \(cs_typeName(O.self))'s value outside it's designated queue."
)
if let customGetter = self.customGetter {
return customGetter(PartialObject<O>(object.rawObject!))
return customGetter(PartialObject<O>(object))
}
return (object.rawObject!.value(forKey: self.keyPath) as! V.QueryableNativeType?)
return (object.value(forKey: self.keyPath) as! V.QueryableNativeType?)
.flatMap(V.cs_fromQueryableNativeType)
}
}
set {
CoreStore.assert(
self.parentObject != nil,
self.rawObject != nil,
"Attempted to access values from a \(cs_typeName(O.self)) meta object. Meta objects are only used for querying keyPaths and infering types."
)
return withExtendedLifetime(self.parentObject! as! O) { (object: O) in
return withExtendedLifetime(self.rawObject!) { (object) in
CoreStore.assert(
object.rawObject!.isRunningInAllowedQueue() == true,
object.isRunningInAllowedQueue() == true,
"Attempted to access \(cs_typeName(O.self))'s value outside it's designated queue."
)
CoreStore.assert(
object.rawObject!.isEditableInContext() == true,
object.isEditableInContext() == true,
"Attempted to update a \(cs_typeName(O.self))'s value from outside a transaction."
)
if let customSetter = self.customSetter {
return customSetter(PartialObject<O>(object.rawObject!), newValue)
return customSetter(PartialObject<O>(object), newValue)
}
object.rawObject!.setValue(
object.setValue(
newValue?.cs_toQueryableNativeType(),
forKey: self.keyPath
)
@@ -412,7 +412,7 @@ public enum ValueContainer<O: CoreStoreObject> {
internal let renamingIdentifier: () -> String?
internal let defaultValue: () -> Any?
internal let affectedByKeyPaths: () -> Set<String>
internal weak var parentObject: CoreStoreObject?
internal var rawObject: CoreStoreManagedObject?
internal private(set) lazy var getter: CoreStoreManagedObject.CustomGetter? = cs_lazy { [unowned self] in