Skip to content
This repository has been archived by the owner on Feb 28, 2020. It is now read-only.

Commit

Permalink
Merge branch 'release/3.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
vmartinelli committed May 25, 2015
2 parents e579a13 + fac7922 commit 385dcd8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion AlecrimCoreData.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "AlecrimCoreData"
s.version = "3.0"
s.version = "3.0.1"
s.summary = "A framework to easily access Core Data objects in Swift."
s.homepage = "https://github.com/Alecrim/AlecrimCoreData"

Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,9 @@ If you want to contribute, please feel free to fork the repository and send pull

### Version History

- 3.0 - Swift framework: added attributes support and many other improvements
- 2.1 - Swift framework: added CocoaPods and Carthage support
- 2.0 - Swift framework: first public release as open source
- 1.1 - Objective-C framework: private Alecrim team use
- 1.0 - Objective-C framework: private Alecrim team use
- 3.x - Swift framework: added attributes support and many other improvements
- 2.x - Swift framework: public open source release
- 1.x - Objective-C framework: private Alecrim team use

---

Expand Down
34 changes: 33 additions & 1 deletion Source/AlecrimCoreData/Classes/Stack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,14 @@ private final class StackBackgroundManagedObjectContext: NSManagedObjectContext
object: self.stack.coordinator
)
}


NSNotificationCenter.defaultCenter().addObserver(
self,
selector: Selector("backgroundManagedObjectContextWillSave:"),
name: NSManagedObjectContextWillSaveNotification,
object: self
)

NSNotificationCenter.defaultCenter().addObserver(
self,
selector: Selector("backgroundManagedObjectContextDidSave:"),
Expand All @@ -319,6 +326,7 @@ private final class StackBackgroundManagedObjectContext: NSManagedObjectContext
}

private func removeObservers() {
NSNotificationCenter.defaultCenter().removeObserver(self, name: NSManagedObjectContextWillSaveNotification, object: self)
NSNotificationCenter.defaultCenter().removeObserver(self, name: NSManagedObjectContextDidSaveNotification, object: self)

if self.stack.contextOptions.stackType == .SQLite && self.stack.contextOptions.ubiquityEnabled {
Expand All @@ -329,9 +337,33 @@ private final class StackBackgroundManagedObjectContext: NSManagedObjectContext

}

@objc private func backgroundManagedObjectContextWillSave(notification: NSNotification) {
if let context = notification.object as? NSManagedObjectContext {
if let insertedObjects = context.insertedObjects as? Set<NSManagedObject> {
if insertedObjects.count > 0 {
var error: NSError? = nil
if !context.obtainPermanentIDsForObjects((insertedObjects as NSSet).allObjects, error: &error) {
println(error)
}
}
}
}
}

@objc private func backgroundManagedObjectContextDidSave(notification: NSNotification) {
if let mainContext = self.stack.mainManagedObjectContext {
mainContext.performBlockAndWait {
if let userInfo = notification.userInfo {
let dict = userInfo as NSDictionary
if let updatedObjects = dict[NSUpdatedObjectsKey] as? Set<NSManagedObject> {
if updatedObjects.count > 0 {
for object in updatedObjects {
mainContext.objectWithID(object.objectID).willAccessValueForKey(nil) // ensure that a fault has been fired
}
}
}
}

mainContext.mergeChangesFromContextDidSaveNotification(notification)
}
}
Expand Down

0 comments on commit 385dcd8

Please sign in to comment.