mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-25 19:01:41 +01:00
refactored autoreleasepool calls
This commit is contained in:
@@ -70,19 +70,17 @@ public extension BaseDataTransaction {
|
|||||||
"Attempted to import an object of type \(typeName(into.entityClass)) outside the transaction's designated queue."
|
"Attempted to import an object of type \(typeName(into.entityClass)) outside the transaction's designated queue."
|
||||||
)
|
)
|
||||||
|
|
||||||
var returnValue: T?
|
return try autoreleasepool {
|
||||||
try autoreleasepool {
|
|
||||||
|
|
||||||
if !T.shouldImportFromSource(source) {
|
if !T.shouldImportFromSource(source) {
|
||||||
|
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
let object = self.create(into)
|
let object = self.create(into)
|
||||||
try object.didInsertFromImportSource(source)
|
try object.didInsertFromImportSource(source)
|
||||||
returnValue = object
|
return object
|
||||||
}
|
}
|
||||||
return returnValue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func importUniqueObject<T where T: NSManagedObject, T: ImportableUniqueObject>(
|
func importUniqueObject<T where T: NSManagedObject, T: ImportableUniqueObject>(
|
||||||
@@ -94,12 +92,11 @@ public extension BaseDataTransaction {
|
|||||||
"Attempted to import an object of type \(typeName(into.entityClass)) outside the transaction's designated queue."
|
"Attempted to import an object of type \(typeName(into.entityClass)) outside the transaction's designated queue."
|
||||||
)
|
)
|
||||||
|
|
||||||
var returnValue: T?
|
return try autoreleasepool {
|
||||||
try autoreleasepool {
|
|
||||||
|
|
||||||
if !T.shouldImportFromSource(source) {
|
if !T.shouldImportFromSource(source) {
|
||||||
|
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
let uniqueIDKeyPath = T.uniqueIDKeyPath
|
let uniqueIDKeyPath = T.uniqueIDKeyPath
|
||||||
@@ -109,17 +106,16 @@ public extension BaseDataTransaction {
|
|||||||
if let object = self.fetchOne(From(T), Where(uniqueIDKeyPath, isEqualTo: uniqueIDValue)) {
|
if let object = self.fetchOne(From(T), Where(uniqueIDKeyPath, isEqualTo: uniqueIDValue)) {
|
||||||
|
|
||||||
try object.updateFromImportSource(source)
|
try object.updateFromImportSource(source)
|
||||||
returnValue = object
|
return object
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
let object = self.create(into)
|
let object = self.create(into)
|
||||||
object.uniqueIDValue = uniqueIDValue
|
object.uniqueIDValue = uniqueIDValue
|
||||||
try object.didInsertFromImportSource(source)
|
try object.didInsertFromImportSource(source)
|
||||||
returnValue = object
|
return object
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnValue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func importUniqueObjects<T where T: NSManagedObject, T: ImportableUniqueObject>(
|
func importUniqueObjects<T where T: NSManagedObject, T: ImportableUniqueObject>(
|
||||||
|
|||||||
@@ -25,6 +25,40 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
internal func autoreleasepool<T>(@noescape closure: () -> T?) -> T? {
|
||||||
|
|
||||||
|
var closureValue: T?
|
||||||
|
ObjectiveC.autoreleasepool {
|
||||||
|
|
||||||
|
closureValue = closure()
|
||||||
|
}
|
||||||
|
|
||||||
|
return closureValue
|
||||||
|
}
|
||||||
|
|
||||||
|
internal func autoreleasepool<T>(@noescape closure: () throws -> T?) throws -> T? {
|
||||||
|
|
||||||
|
var closureValue: T?
|
||||||
|
var closureError: ErrorType?
|
||||||
|
ObjectiveC.autoreleasepool {
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
closureValue = try closure()
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
|
||||||
|
closureError = error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let closureError = closureError {
|
||||||
|
|
||||||
|
throw closureError
|
||||||
|
}
|
||||||
|
return closureValue
|
||||||
|
}
|
||||||
|
|
||||||
internal func autoreleasepool(@noescape closure: () throws -> Void) throws {
|
internal func autoreleasepool(@noescape closure: () throws -> Void) throws {
|
||||||
|
|
||||||
var closureError: ErrorType?
|
var closureError: ErrorType?
|
||||||
|
|||||||
Reference in New Issue
Block a user