Compare commits

...

13 Commits
1.6.2 ... 1.6.8

Author SHA1 Message Date
John Rommel Estropia
f617f2cc53 Simpler API for creating CoreStore-managed NSFetchedResultsControllers, useful for external SDK's that require them 2016-05-28 01:47:48 +09:00
John Rommel Estropia
f396b01043 fixed Cartfile dependency 2016-05-26 01:28:26 +09:00
John Rommel Estropia
e38093342d version bump, updated dependendencies 2016-05-24 00:42:35 +09:00
John Rommel Estropia
c15afcb381 Allow flushing UnsafeDataTransactions to notify its ListMonitors and ObjectMonitors without saving changes to the DataStack (fixes #71) 2016-05-24 00:40:13 +09:00
John Rommel Estropia
a97001cdbb fixed scheme 2016-05-24 00:32:54 +09:00
John Estropia
c8ca16a982 Merge pull request #69 from bretsko/master
fixed Readme
2016-05-17 14:05:11 +09:00
Oleksandr Bretsko
9e0493a20d fixed Readme
replaced importObjects with importUniqueObjects
2016-05-17 08:43:40 +04:00
John Rommel Estropia
c990f7764a version bump 2016-05-07 12:19:30 +08:00
John Rommel Estropia
26ae6293ca merge changes to main context synchronously or asynchronously depending on the caller intention (fixes #65) 2016-05-07 12:18:54 +08:00
John Rommel Estropia
b9a2f96d6e renamed refreshAllObjectsAsFaults to refreshAndMergeAllObjects, which is more correct 2016-05-07 12:04:59 +08:00
John Rommel Estropia
74fe81bfa7 Fix problem when using carthage where the iOS7 framework overwrites the iOS 8 framework 2016-05-02 12:02:31 +08:00
John Rommel Estropia
dff552b95f version bump 2016-04-01 07:42:00 +09:00
John Rommel Estropia
88cac73b20 fix assertion error 2016-04-01 07:41:23 +09:00
18 changed files with 263 additions and 29 deletions

View File

@@ -1 +1 @@
github "JohnEstropia/GCDKit" == 1.2.2
github "JohnEstropia/GCDKit" == 1.2.5

View File

@@ -1 +1 @@
github "JohnEstropia/GCDKit" "1.2.2"
github "JohnEstropia/GCDKit" "1.2.4"

View File

@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "CoreStore"
s.version = "1.6.2"
s.version = "1.6.8"
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"
@@ -18,5 +18,5 @@ Pod::Spec.new do |s|
s.requires_arc = true
s.pod_target_xcconfig = { 'OTHER_SWIFT_FLAGS' => '-D USE_FRAMEWORKS' }
s.dependency "GCDKit", "1.2.2"
s.dependency "GCDKit", "1.2.5"
end

View File

@@ -409,7 +409,7 @@
B5D39A0119FD00C9000E91BB /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
B5D5E0CE1A4D6AAB006468AF /* TestEntity2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestEntity2.swift; sourceTree = "<group>"; };
B5D9C8F61B160ED200E64F0E /* CoreStore.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; path = CoreStore.podspec; sourceTree = SOURCE_ROOT; };
B5D9E3341CA2C317007A9D52 /* CoreStore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CoreStore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B5D9E3341CA2C317007A9D52 /* CoreStore_iOS7.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CoreStore_iOS7.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B5D9E3371CA2C6BF007A9D52 /* GCDBlock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = GCDBlock.swift; path = Carthage/Checkouts/GCDKit/Sources/GCDBlock.swift; sourceTree = "<group>"; };
B5D9E3381CA2C6BF007A9D52 /* GCDGroup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = GCDGroup.swift; path = Carthage/Checkouts/GCDKit/Sources/GCDGroup.swift; sourceTree = "<group>"; };
B5D9E33A1CA2C6BF007A9D52 /* GCDQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = GCDQueue.swift; path = Carthage/Checkouts/GCDKit/Sources/GCDQueue.swift; sourceTree = "<group>"; };
@@ -559,7 +559,7 @@
B52DD17D1BE1F8CC00949AFE /* CoreStoreTests.xctest */,
82BA18891C4BBCBA00A0916E /* CoreStore.framework */,
82BA18921C4BBCBA00A0916E /* CoreStoreTests.xctest */,
B5D9E3341CA2C317007A9D52 /* CoreStore.framework */,
B5D9E3341CA2C317007A9D52 /* CoreStore_iOS7.framework */,
);
name = Products;
sourceTree = "<group>";
@@ -971,7 +971,7 @@
);
name = "CoreStore iOS7";
productName = CoreStore;
productReference = B5D9E3341CA2C317007A9D52 /* CoreStore.framework */;
productReference = B5D9E3341CA2C317007A9D52 /* CoreStore_iOS7.framework */;
productType = "com.apple.product-type.framework";
};
/* End PBXNativeTarget section */
@@ -1020,8 +1020,8 @@
projectDirPath = "";
projectRoot = "";
targets = (
2F03A52F19C5C6DA005002A5 /* CoreStore iOS */,
B5D9E2ED1CA2C317007A9D52 /* CoreStore iOS7 */,
2F03A52F19C5C6DA005002A5 /* CoreStore iOS */,
2F03A53A19C5C6DA005002A5 /* CoreStoreTests iOS */,
82BA18881C4BBCBA00A0916E /* CoreStore tvOS */,
82BA18911C4BBCBA00A0916E /* CoreStoreTests tvOS */,
@@ -1822,6 +1822,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
OTHER_SWIFT_FLAGS = "-D DEBUG";
PRODUCT_NAME = CoreStore_iOS7;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
};
@@ -1839,6 +1840,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
OTHER_SWIFT_FLAGS = "";
PRODUCT_NAME = CoreStore_iOS7;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
};

View File

@@ -15,7 +15,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B5D9E2ED1CA2C317007A9D52"
BuildableName = "CoreStore.framework"
BuildableName = "CoreStore_iOS7.framework"
BlueprintName = "CoreStore iOS7"
ReferencedContainer = "container:CoreStore.xcodeproj">
</BuildableReference>
@@ -79,7 +79,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B5D9E2ED1CA2C317007A9D52"
BuildableName = "CoreStore.framework"
BuildableName = "CoreStore_iOS7.framework"
BlueprintName = "CoreStore iOS7"
ReferencedContainer = "container:CoreStore.xcodeproj">
</BuildableReference>

View File

@@ -32,8 +32,170 @@ import CoreData
public extension NSFetchedResultsController {
/**
Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful to partially support Objective-C classes by passing an `NSFetchedResultsController` instance instead of a `ListMonitor`.
Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter dataStack: the `DataStack` to observe objects from
- parameter from: a `From` clause indicating the entity type
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes a `DataStack`
*/
@nonobjc
public static func createFor<T: NSManagedObject>(dataStack: DataStack, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController {
return CoreStoreFetchedResultsController<T>(
context: dataStack.mainContext,
fetchRequest: CoreStoreFetchRequest(),
from: from,
sectionBy: sectionBy,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter dataStack: the `DataStack` to observe objects from
- parameter from: a `From` clause indicating the entity type
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes a `DataStack`
*/
@nonobjc
public static func createFor<T: NSManagedObject>(dataStack: DataStack, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController {
return CoreStoreFetchedResultsController<T>(
context: dataStack.mainContext,
fetchRequest: CoreStoreFetchRequest(),
from: from,
sectionBy: sectionBy,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter dataStack: the `DataStack` to observe objects from
- parameter from: a `From` clause indicating the entity type
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes a `DataStack`
*/
@nonobjc
public static func createFor<T: NSManagedObject>(dataStack: DataStack, _ from: From<T>, _ fetchClauses: FetchClause...) -> NSFetchedResultsController {
return CoreStoreFetchedResultsController<T>(
context: dataStack.mainContext,
fetchRequest: CoreStoreFetchRequest(),
from: from,
sectionBy: nil,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter dataStack: the `DataStack` to observe objects from
- parameter from: a `From` clause indicating the entity type
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes a `DataStack`
*/
@nonobjc
public static func createFor<T: NSManagedObject>(dataStack: DataStack, _ from: From<T>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController {
return CoreStoreFetchedResultsController<T>(
context: dataStack.mainContext,
fetchRequest: CoreStoreFetchRequest(),
from: from,
sectionBy: nil,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from an `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter transaction: the `UnsafeDataTransaction` to observe objects from
- parameter from: a `From` clause indicating the entity type
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes an `UnsafeDataTransaction`
*/
@nonobjc
public static func createFor<T: NSManagedObject>(transaction: UnsafeDataTransaction, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController {
return CoreStoreFetchedResultsController<T>(
context: transaction.context,
fetchRequest: CoreStoreFetchRequest(),
from: from,
sectionBy: sectionBy,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from an `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter transaction: the `UnsafeDataTransaction` to observe objects from
- parameter from: a `From` clause indicating the entity type
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes an `UnsafeDataTransaction`
*/
@nonobjc
public static func createFor<T: NSManagedObject>(transaction: UnsafeDataTransaction, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController {
return CoreStoreFetchedResultsController<T>(
context: transaction.context,
fetchRequest: CoreStoreFetchRequest(),
from: from,
sectionBy: sectionBy,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from an `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter transaction: the `UnsafeDataTransaction` to observe objects from
- parameter from: a `From` clause indicating the entity type
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes an `UnsafeDataTransaction`
*/
@nonobjc
public static func createFor<T: NSManagedObject>(transaction: UnsafeDataTransaction, _ from: From<T>, _ fetchClauses: FetchClause...) -> NSFetchedResultsController {
return CoreStoreFetchedResultsController<T>(
context: transaction.context,
fetchRequest: CoreStoreFetchRequest(),
from: from,
sectionBy: nil,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from an `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter transaction: the `UnsafeDataTransaction` to observe objects from
- parameter from: a `From` clause indicating the entity type
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
*/
@nonobjc
public static func createFor<T: NSManagedObject>(transaction: UnsafeDataTransaction, _ from: From<T>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController {
return CoreStoreFetchedResultsController<T>(
context: transaction.context,
fetchRequest: CoreStoreFetchRequest(),
from: from,
sectionBy: nil,
fetchClauses: fetchClauses
)
}
@available(*, deprecated=1.6.8, message="Use NSFetchedResultsController.createFor(_:_:_:_:) instead.")
@nonobjc
public static func createForStack<T: NSManagedObject>(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From<T>? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController {
return CoreStoreFetchedResultsController<T>(
@@ -45,7 +207,8 @@ public extension NSFetchedResultsController {
)
}
@available(*, deprecated=1.5.2, message="Use NSFetchedResultsController.createForStack(_:fetchRequest:from:sectionBy:fetchClauses:) to create NSFetchedResultsControllers directly")
@available(*, deprecated=1.5.2, message="Use NSFetchedResultsController.createFor(_:_:_:_:) to create NSFetchedResultsControllers directly")
@nonobjc
public convenience init<T: NSManagedObject>(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From<T>? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) {
let context = dataStack.mainContext

View File

@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.6.2</string>
<string>1.6.8</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>

View File

@@ -48,6 +48,10 @@ internal final class CoreStoreFetchedResultsController<T: NSManagedObject>: NSFe
internal init<T>(context: NSManagedObjectContext, fetchRequest: NSFetchRequest, from: From<T>? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) {
CoreStore.assert(
fetchClauses.filter { $0 is OrderBy }.count > 0,
"An \(typeName(NSFetchedResultsController)) requires an OrderBy clause."
)
from?.applyToFetchRequest(fetchRequest, context: context, applyAffectedStores: false)
for clause in fetchClauses {

View File

@@ -82,14 +82,28 @@ internal extension NSManagedObjectContext {
object: rootContext,
closure: { [weak context] (note) -> Void in
context?.performBlock { () -> Void in
guard let rootContext = note.object as? NSManagedObjectContext,
let context = context else {
return
}
let mergeChanges = { () -> Void in
let updatedObjects = (note.userInfo?[NSUpdatedObjectsKey] as? Set<NSManagedObject>) ?? []
for object in updatedObjects {
context?.objectWithID(object.objectID).willAccessValueForKey(nil)
context.objectWithID(object.objectID).willAccessValueForKey(nil)
}
context?.mergeChangesFromContextDidSaveNotification(note)
context.mergeChangesFromContextDidSaveNotification(note)
}
if rootContext.isSavingSynchronously == true {
context.performBlockAndWait(mergeChanges)
}
else {
context.performBlock(mergeChanges)
}
}
)

View File

@@ -55,6 +55,26 @@ internal extension NSManagedObjectContext {
}
}
internal var isSavingSynchronously: Bool? {
get {
let value: NSNumber? = getAssociatedObjectForKey(
&PropertyKeys.isSavingSynchronously,
inObject: self
)
return value?.boolValue
}
set {
setAssociatedWeakObject(
newValue.flatMap { NSNumber(bool: $0) },
forKey: &PropertyKeys.isSavingSynchronously,
inObject: self
)
}
}
internal func isRunningInAllowedQueue() -> Bool {
guard let parentTransaction = self.parentTransaction else {
@@ -89,7 +109,9 @@ internal extension NSManagedObjectContext {
do {
self.isSavingSynchronously = true
try self.save()
self.isSavingSynchronously = nil
}
catch {
@@ -137,7 +159,9 @@ internal extension NSManagedObjectContext {
do {
self.isSavingSynchronously = false
try self.save()
self.isSavingSynchronously = nil
}
catch {
@@ -167,7 +191,7 @@ internal extension NSManagedObjectContext {
}
}
internal func refreshAllObjectsAsFaults() {
internal func refreshAndMergeAllObjects() {
if #available(iOS 8.3, OSX 10.11, *) {
@@ -175,7 +199,7 @@ internal extension NSManagedObjectContext {
}
else {
self.registeredObjects.forEach { self.refreshObject($0, mergeChanges: false) }
self.registeredObjects.forEach { self.refreshObject($0, mergeChanges: true) }
}
}
@@ -185,5 +209,6 @@ internal extension NSManagedObjectContext {
private struct PropertyKeys {
static var parentTransaction: Void?
static var isSavingSynchronously: Void?
}
}

View File

@@ -36,14 +36,14 @@ internal final class NotificationObserver {
let object: AnyObject?
let observer: NSObjectProtocol
init(notificationName: String, object: AnyObject?, closure: (note: NSNotification) -> Void) {
init(notificationName: String, object: AnyObject?, queue: NSOperationQueue? = nil, closure: (note: NSNotification) -> Void) {
self.notificationName = notificationName
self.object = object
self.observer = NSNotificationCenter.defaultCenter().addObserverForName(
notificationName,
object: object,
queue: nil,
queue: queue,
usingBlock: closure
)
}

View File

@@ -1033,6 +1033,7 @@ public final class ListMonitor<T: NSManagedObject> {
self.observerForWillChangePersistentStore = NotificationObserver(
notificationName: NSPersistentStoreCoordinatorStoresWillChangeNotification,
object: coordinator,
queue: NSOperationQueue.mainQueue(),
closure: { [weak self] (note) -> Void in
guard let `self` = self else {
@@ -1054,6 +1055,7 @@ public final class ListMonitor<T: NSManagedObject> {
self.observerForDidChangePersistentStore = NotificationObserver(
notificationName: NSPersistentStoreCoordinatorStoresDidChangeNotification,
object: coordinator,
queue: NSOperationQueue.mainQueue(),
closure: { [weak self] (note) -> Void in
guard let `self` = self else {

View File

@@ -191,14 +191,14 @@ public /*abstract*/ class BaseDataTransaction {
/**
Refreshes all registered objects `NSManagedObject`s in the transaction.
*/
public func refreshAllObjectsAsFaults() {
public func refreshAndMergeAllObjects() {
CoreStore.assert(
self.isRunningInAllowedQueue(),
"Attempted to refresh entities outside their designated queue."
)
self.context.refreshAllObjectsAsFaults()
self.context.refreshAndMergeAllObjects()
}

View File

@@ -66,9 +66,9 @@ public extension CoreStore {
/**
Refreshes all registered objects `NSManagedObject`s in the `DataStack`.
*/
public static func refreshAllObjectsAsFaults() {
public static func refreshAndMergeAllObjects() {
self.defaultStack.refreshAllObjectsAsFaults()
self.defaultStack.refreshAndMergeAllObjects()
}
@available(*, deprecated=1.3.1, renamed="beginUnsafe")

View File

@@ -83,14 +83,14 @@ public extension DataStack {
/**
Refreshes all registered objects `NSManagedObject`s in the `DataStack`.
*/
public func refreshAllObjectsAsFaults() {
public func refreshAndMergeAllObjects() {
CoreStore.assert(
NSThread.isMainThread(),
"Attempted to refresh entities outside their designated queue."
)
self.mainContext.refreshAllObjectsAsFaults()
self.mainContext.refreshAndMergeAllObjects()
}
@available(*, deprecated=1.3.1, renamed="beginUnsafe")

View File

@@ -91,6 +91,30 @@ public final class UnsafeDataTransaction: BaseDataTransaction {
self.context.undo()
}
/**
Immediately flushes all pending changes to the transaction's observers. This is useful in conjunction with `ListMonitor`s and `ObjectMonitor`s created from `UnsafeDataTransaction`s used to manage temporary "scratch" data.
- Important: Note that unlike `commit()`, `flush()` does not propagate/save updates to the `DataStack` and the persistent store. However, the flushed changes will be seen by children transactions created further from the current transaction (i.e. through `transaction.beginUnsafe()`)
- throws: an error thrown from `closure`, or an error thrown by Core Data (usually validation errors or conflict errors)
*/
public func flush() throws {
try self.context.save()
}
/**
Flushes all pending changes to the transaction's observers at the end of the `closure`'s execution. This is useful in conjunction with `ListMonitor`s and `ObjectMonitor`s created from `UnsafeDataTransaction`s used to manage temporary "scratch" data.
- Important: Note that unlike `commit()`, `flush()` does not propagate/save updates to the `DataStack` and the persistent store. However, the flushed changes will be seen by children transactions created further from the current transaction (i.e. through `transaction.beginUnsafe()`)
- parameter closure: the closure where changes can be made prior to the flush
- throws: an error thrown from `closure`, or an error thrown by Core Data (usually validation errors or conflict errors)
*/
public func flush(@noescape closure: () throws -> Void) throws {
try closure()
try self.context.save()
}
/**
Redo's the last undone change to the transaction.
*/
@@ -122,7 +146,7 @@ public final class UnsafeDataTransaction: BaseDataTransaction {
/**
Returns the `NSManagedObjectContext` for this unsafe transaction. Use only for cases where external frameworks need an `NSManagedObjectContext` instance to work with.
Note that it is the developer's responsibility to ensure the following:
- Important: Note that it is the developer's responsibility to ensure the following:
- that the `UnsafeDataTransaction` that owns this context should be strongly referenced and prevented from being deallocated during the context's lifetime
- that all saves will be done either through the `UnsafeDataTransaction`'s `commit(...)` method, or by calling `save()` manually on the context, its parent, and all other ancestor contexts if there are any.
*/

View File

@@ -733,7 +733,7 @@ or multiple objects at once with the `importUniqueObjects(...)` method:
```swift
CoreStore.beginAsynchronous { (transaction) -> Void in
let jsonArray: [[String: AnyObject]] = // ...
try! transaction.importObjects(
try! transaction.importUniqueObjects(
Into(MyPersonEntity),
sourceArray: jsonArray
)