mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-02-26 01:25:01 +01:00
fix issue with early-deallocated CoreStoreObjects
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "CoreStore"
|
||||
s.version = "5.3.0"
|
||||
s.swift_version = "4.1"
|
||||
s.version = "5.3.1"
|
||||
s.swift_version = "4.2"
|
||||
s.license = "MIT"
|
||||
s.summary = "Unleashing the real power of Core Data with the elegance and safety of Swift"
|
||||
s.homepage = "https://github.com/JohnEstropia/CoreStore"
|
||||
|
||||
@@ -41,7 +41,7 @@ internal protocol AttributeProtocol: class {
|
||||
var renamingIdentifier: () -> String? { get }
|
||||
var defaultValue: () -> Any? { get }
|
||||
var affectedByKeyPaths: () -> Set<String> { get }
|
||||
var parentObject: CoreStoreObject? { get set }
|
||||
var rawObject: CoreStoreManagedObject? { get set }
|
||||
var getter: CoreStoreManagedObject.CustomGetter? { get }
|
||||
var setter: CoreStoreManagedObject.CustomSetter? { get }
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ open /*abstract*/ class CoreStoreObject: DynamicObject, Hashable {
|
||||
}
|
||||
if lhs.isMeta {
|
||||
|
||||
return type(of: lhs) == type(of: rhs)
|
||||
return cs_dynamicType(of: lhs) == cs_dynamicType(of: rhs)
|
||||
}
|
||||
return lhs.rawObject!.isEqual(rhs.rawObject!)
|
||||
}
|
||||
@@ -124,10 +124,10 @@ open /*abstract*/ class CoreStoreObject: DynamicObject, Hashable {
|
||||
switch child.value {
|
||||
|
||||
case let property as AttributeProtocol:
|
||||
property.parentObject = parentObject
|
||||
property.rawObject = parentObject.rawObject
|
||||
|
||||
case let property as RelationshipProtocol:
|
||||
property.parentObject = parentObject
|
||||
property.rawObject = parentObject.rawObject
|
||||
|
||||
default:
|
||||
continue
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>5.3.0</string>
|
||||
<string>5.3.1</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
|
||||
@@ -244,23 +244,23 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
||||
internal let versionHashModifier: () -> String?
|
||||
internal let renamingIdentifier: () -> String?
|
||||
internal let affectedByKeyPaths: () -> Set<String>
|
||||
internal weak var parentObject: CoreStoreObject?
|
||||
internal var rawObject: CoreStoreManagedObject?
|
||||
|
||||
internal var nativeValue: NSManagedObject? {
|
||||
|
||||
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."
|
||||
)
|
||||
return object.rawObject!.getValue(
|
||||
return object.getValue(
|
||||
forKvcKey: self.keyPath,
|
||||
didGetValue: { $0 as! NSManagedObject? }
|
||||
)
|
||||
@@ -269,20 +269,20 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
||||
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."
|
||||
)
|
||||
object.rawObject!.setValue(
|
||||
object.setValue(
|
||||
newValue,
|
||||
forKvcKey: self.keyPath
|
||||
)
|
||||
@@ -512,23 +512,23 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
||||
internal let versionHashModifier: () -> String?
|
||||
internal let renamingIdentifier: () -> String?
|
||||
internal let affectedByKeyPaths: () -> Set<String>
|
||||
internal weak var parentObject: CoreStoreObject?
|
||||
internal var rawObject: CoreStoreManagedObject?
|
||||
|
||||
internal var nativeValue: NSOrderedSet {
|
||||
|
||||
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."
|
||||
)
|
||||
return object.rawObject!.getValue(
|
||||
return object.getValue(
|
||||
forKvcKey: self.keyPath,
|
||||
didGetValue: { ($0 as! NSOrderedSet?) ?? [] }
|
||||
)
|
||||
@@ -537,20 +537,20 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
||||
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."
|
||||
)
|
||||
object.rawObject!.setValue(
|
||||
object.setValue(
|
||||
newValue,
|
||||
forKvcKey: self.keyPath
|
||||
)
|
||||
@@ -785,23 +785,23 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
||||
internal let versionHashModifier: () -> String?
|
||||
internal let renamingIdentifier: () -> String?
|
||||
internal let affectedByKeyPaths: () -> Set<String>
|
||||
internal weak var parentObject: CoreStoreObject?
|
||||
internal var rawObject: CoreStoreManagedObject?
|
||||
|
||||
internal var nativeValue: NSSet {
|
||||
|
||||
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."
|
||||
)
|
||||
return object.rawObject!.getValue(
|
||||
return object.getValue(
|
||||
forKvcKey: self.keyPath,
|
||||
didGetValue: { ($0 as! NSSet?) ?? [] }
|
||||
)
|
||||
@@ -810,20 +810,20 @@ public enum RelationshipContainer<O: CoreStoreObject> {
|
||||
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."
|
||||
)
|
||||
object.rawObject!.setValue(
|
||||
object.setValue(
|
||||
newValue,
|
||||
forKvcKey: self.keyPath
|
||||
)
|
||||
|
||||
@@ -37,7 +37,7 @@ internal protocol RelationshipProtocol: class {
|
||||
var deleteRule: NSDeleteRule { get }
|
||||
var inverse: (type: CoreStoreObject.Type, keyPath: () -> KeyPathString?) { get }
|
||||
var affectedByKeyPaths: () -> Set<String> { get }
|
||||
var parentObject: CoreStoreObject? { get set }
|
||||
var rawObject: CoreStoreManagedObject? { get set }
|
||||
var versionHashModifier: () -> String? { get }
|
||||
var renamingIdentifier: () -> String? { get }
|
||||
var minCount: Int { get }
|
||||
|
||||
@@ -145,43 +145,43 @@ public enum TransformableContainer<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
|
||||
return object.value(forKey: self.keyPath)! as! V
|
||||
}
|
||||
}
|
||||
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,
|
||||
forKey: self.keyPath
|
||||
)
|
||||
@@ -205,7 +205,7 @@ public enum TransformableContainer<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
|
||||
|
||||
@@ -358,43 +358,43 @@ public enum TransformableContainer<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?
|
||||
return object.value(forKey: self.keyPath) as! V?
|
||||
}
|
||||
}
|
||||
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,
|
||||
forKey: self.keyPath
|
||||
)
|
||||
@@ -418,7 +418,7 @@ public enum TransformableContainer<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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user