mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-21 17:09:42 +01:00
bug fix for dictionaries getting deallocated earlier
This commit is contained in:
@@ -102,16 +102,38 @@ public struct Where: FetchClause, QueryClause, DeleteClause {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initializes a `Where` clause with a predicate using the specified string format and arguments
|
Initializes a `Where` clause that compares equality
|
||||||
|
|
||||||
- parameter format: the format string for the predicate
|
- parameter keyPath: the keyPath to compare with
|
||||||
- parameter argumentArray: the arguments for `format`
|
- parameter value: the arguments for the `==` operator
|
||||||
*/
|
*/
|
||||||
public init(_ keyPath: KeyPath, isEqualTo value: NSObject?) {
|
public init(_ keyPath: KeyPath, isEqualTo value: NSObject?) {
|
||||||
|
|
||||||
self.init(value == nil
|
self.init(value == nil
|
||||||
? NSPredicate(format: "\(keyPath) == nil")
|
? NSPredicate(format: "\(keyPath) == nil")
|
||||||
: NSPredicate(format: "\(keyPath) == %@", value!))
|
: NSPredicate(format: "\(keyPath) == %@", argumentArray: [value!]))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initializes a `Where` clause that compares membership
|
||||||
|
|
||||||
|
- parameter keyPath: the keyPath to compare with
|
||||||
|
- parameter list: the array to check membership of
|
||||||
|
*/
|
||||||
|
public init(_ keyPath: KeyPath, isMemberOf list: NSArray) {
|
||||||
|
|
||||||
|
self.init(NSPredicate(format: "\(keyPath) IN %@", list))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initializes a `Where` clause that compares membership
|
||||||
|
|
||||||
|
- parameter keyPath: the keyPath to compare with
|
||||||
|
- parameter list: the sequence to check membership of
|
||||||
|
*/
|
||||||
|
public init<S: SequenceType where S.Generator.Element: NSObject>(_ keyPath: KeyPath, isMemberOf list: S) {
|
||||||
|
|
||||||
|
self.init(NSPredicate(format: "\(keyPath) IN %@", Array(list) as NSArray))
|
||||||
}
|
}
|
||||||
|
|
||||||
public let predicate: NSPredicate
|
public let predicate: NSPredicate
|
||||||
|
|||||||
@@ -221,15 +221,18 @@ public extension BaseDataTransaction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mappingCopy = mapping // bugfix: prevent deallocation of exhausted items when accessed lazily with .keys and .values
|
||||||
if let preProcess = preProcess {
|
if let preProcess = preProcess {
|
||||||
|
|
||||||
try autoreleasepool {
|
try autoreleasepool {
|
||||||
|
|
||||||
try preProcess(mapping: &mapping)
|
try preProcess(mapping: &mappingCopy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mapping = mappingCopy
|
||||||
|
|
||||||
for object in self.fetchAll(From(T), Where("%K IN %@", T.uniqueIDKeyPath, Array(mapping.keys))) ?? [] {
|
var mappingCopyForKeys = mapping
|
||||||
|
for object in self.fetchAll(From(T), Where(T.uniqueIDKeyPath, isMemberOf: mappingCopyForKeys.keys)) ?? [] {
|
||||||
|
|
||||||
try autoreleasepool {
|
try autoreleasepool {
|
||||||
|
|
||||||
@@ -291,16 +294,19 @@ public extension BaseDataTransaction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mappingCopy = mapping // bugfix: prevent deallocation of exhausted items when accessed lazily with .keys and .values
|
||||||
if let preProcess = preProcess {
|
if let preProcess = preProcess {
|
||||||
|
|
||||||
try autoreleasepool {
|
try autoreleasepool {
|
||||||
|
|
||||||
try preProcess(mapping: &mapping)
|
try preProcess(mapping: &mappingCopy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mapping = mappingCopy
|
||||||
|
|
||||||
|
var mappingCopyForKeys = mapping
|
||||||
var objects = Dictionary<T.UniqueIDType, T>()
|
var objects = Dictionary<T.UniqueIDType, T>()
|
||||||
for object in self.fetchAll(From(T), Where("%K IN %@", T.uniqueIDKeyPath, Array(mapping.keys))) ?? [] {
|
for object in self.fetchAll(From(T), Where(T.uniqueIDKeyPath, isMemberOf: mappingCopyForKeys.keys)) ?? [] {
|
||||||
|
|
||||||
try autoreleasepool {
|
try autoreleasepool {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user