From b475afe79f33a0dfdbda1275bb56e913ba29c3e0 Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Mon, 17 Aug 2015 23:51:08 +0900 Subject: [PATCH 01/13] updated Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f11ee1c..ded62d4 100644 --- a/README.md +++ b/README.md @@ -956,7 +956,7 @@ let person2 = self.monitor[1, 2] # Installation - Requires: - iOS 8 SDK and above - - Swift 1.2 + - Swift 2.0 - Dependencies: - [GCDKit](https://github.com/JohnEstropia/GCDKit) From ba4fb5e5cb24f9fa246f1a8d7914e9cd8de34951 Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Fri, 21 Aug 2015 08:03:14 +0900 Subject: [PATCH 02/13] version bump --- CoreStore.podspec | 2 +- CoreStore/Info.plist | 2 +- README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CoreStore.podspec b/CoreStore.podspec index e8e2abf..17769c0 100644 --- a/CoreStore.podspec +++ b/CoreStore.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "CoreStore" - s.version = "1.1.2" + s.version = "1.2.0" s.license = "MIT" s.summary = "Simple, elegant, and smart Core Data programming with Swift" s.homepage = "https://github.com/JohnEstropia/CoreStore" diff --git a/CoreStore/Info.plist b/CoreStore/Info.plist index 3034b22..331a2da 100644 --- a/CoreStore/Info.plist +++ b/CoreStore/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.1.2 + 1.2.0 CFBundleSignature ???? CFBundleVersion diff --git a/README.md b/README.md index ded62d4..a07ea9f 100644 --- a/README.md +++ b/README.md @@ -956,7 +956,7 @@ let person2 = self.monitor[1, 2] # Installation - Requires: - iOS 8 SDK and above - - Swift 2.0 + - Swift 2.0 (XCode 7 beta 5) - Dependencies: - [GCDKit](https://github.com/JohnEstropia/GCDKit) From 1121d44d7bfcef122ffdea1daef10fed5995b6d3 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Fri, 21 Aug 2015 18:19:21 +0900 Subject: [PATCH 03/13] pass transaction to ImportableObject methods --- .../BaseDataTransaction+Importing.swift | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/CoreStore/Importing Data/BaseDataTransaction+Importing.swift b/CoreStore/Importing Data/BaseDataTransaction+Importing.swift index 4fdfe7b..c0b696e 100644 --- a/CoreStore/Importing Data/BaseDataTransaction+Importing.swift +++ b/CoreStore/Importing Data/BaseDataTransaction+Importing.swift @@ -31,16 +31,16 @@ public protocol ImportableObject: class { typealias ImportSource - static func shouldImportFromSource(source: ImportSource) -> Bool + static func shouldImportFromSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) -> Bool - func didInsertFromImportSource(source: ImportSource) throws + func didInsertFromImportSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) throws - func updateFromImportSource(source: ImportSource) throws + func updateFromImportSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) throws } public extension ImportableObject { - static func shouldImportFromSource(source: ImportSource) -> Bool { + static func shouldImportFromSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) -> Bool { return true } @@ -55,7 +55,7 @@ public protocol ImportableUniqueObject: ImportableObject { var uniqueIDValue: UniqueIDType { get set } - static func uniqueIDFromImportSource(source: ImportSource) throws -> UniqueIDType + static func uniqueIDFromImportSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) throws -> UniqueIDType } @@ -72,13 +72,13 @@ public extension BaseDataTransaction { return try autoreleasepool { - if !T.shouldImportFromSource(source) { + if !T.shouldImportFromSource(source, inTransaction: self) { return nil } let object = self.create(into) - try object.didInsertFromImportSource(source) + try object.didInsertFromImportSource(source, inTransaction: self) return object } } @@ -99,7 +99,7 @@ public extension BaseDataTransaction { try autoreleasepool { let object = self.create(into) - try object.didInsertFromImportSource(source) + try object.didInsertFromImportSource(source, inTransaction: self) } } } @@ -123,7 +123,7 @@ public extension BaseDataTransaction { try autoreleasepool { let object = self.create(into) - try object.didInsertFromImportSource(source) + try object.didInsertFromImportSource(source, inTransaction: self) objects.append(object) } @@ -143,24 +143,24 @@ public extension BaseDataTransaction { return try autoreleasepool { - if !T.shouldImportFromSource(source) { + if !T.shouldImportFromSource(source, inTransaction: self) { return nil } let uniqueIDKeyPath = T.uniqueIDKeyPath - let uniqueIDValue = try T.uniqueIDFromImportSource(source) + let uniqueIDValue = try T.uniqueIDFromImportSource(source, inTransaction: self) if let object = self.fetchOne(From(T), Where(uniqueIDKeyPath, isEqualTo: uniqueIDValue)) { - try object.updateFromImportSource(source) + try object.updateFromImportSource(source, inTransaction: self) return object } else { let object = self.create(into) object.uniqueIDValue = uniqueIDValue - try object.didInsertFromImportSource(source) + try object.didInsertFromImportSource(source, inTransaction: self) return object } } @@ -183,12 +183,12 @@ public extension BaseDataTransaction { try autoreleasepool { - if !T.shouldImportFromSource(source) { + if !T.shouldImportFromSource(source, inTransaction: self) { return } - let uniqueIDValue = try T.uniqueIDFromImportSource(source) + let uniqueIDValue = try T.uniqueIDFromImportSource(source, inTransaction: self) mapping[uniqueIDValue] = source } } @@ -206,7 +206,7 @@ public extension BaseDataTransaction { try autoreleasepool { let uniqueIDValue = object.uniqueIDValue - try object.updateFromImportSource(mapping.removeValueForKey(uniqueIDValue)!) + try object.updateFromImportSource(mapping.removeValueForKey(uniqueIDValue)!, inTransaction: self) } } @@ -216,7 +216,7 @@ public extension BaseDataTransaction { let object = self.create(into) object.uniqueIDValue = uniqueIDValue - try object.didInsertFromImportSource(source) + try object.didInsertFromImportSource(source, inTransaction: self) } } } @@ -241,12 +241,12 @@ public extension BaseDataTransaction { try autoreleasepool { - if !T.shouldImportFromSource(source) { + if !T.shouldImportFromSource(source, inTransaction: self) { return } - let uniqueIDValue = try T.uniqueIDFromImportSource(source) + let uniqueIDValue = try T.uniqueIDFromImportSource(source, inTransaction: self) mapping[uniqueIDValue] = source sortedIDs.append(uniqueIDValue) } @@ -266,7 +266,7 @@ public extension BaseDataTransaction { try autoreleasepool { let uniqueIDValue = object.uniqueIDValue - try object.updateFromImportSource(mapping.removeValueForKey(uniqueIDValue)!) + try object.updateFromImportSource(mapping.removeValueForKey(uniqueIDValue)!, inTransaction: self) objects[uniqueIDValue] = object } } @@ -277,7 +277,7 @@ public extension BaseDataTransaction { let object = self.create(into) object.uniqueIDValue = uniqueIDValue - try object.didInsertFromImportSource(source) + try object.didInsertFromImportSource(source, inTransaction: self) objects[uniqueIDValue] = object } From 4c16a961ba43234a6e00e4564d7a5d8e07229fca Mon Sep 17 00:00:00 2001 From: John Estropia Date: Fri, 21 Aug 2015 18:28:02 +0900 Subject: [PATCH 04/13] added default implementation to didInsertFromImportSource --- CoreStore/Importing Data/BaseDataTransaction+Importing.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CoreStore/Importing Data/BaseDataTransaction+Importing.swift b/CoreStore/Importing Data/BaseDataTransaction+Importing.swift index c0b696e..2bb94ec 100644 --- a/CoreStore/Importing Data/BaseDataTransaction+Importing.swift +++ b/CoreStore/Importing Data/BaseDataTransaction+Importing.swift @@ -44,6 +44,11 @@ public extension ImportableObject { return true } + + func didInsertFromImportSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) throws { + + try self.updateFromImportSource(source, inTransaction: transaction) + } } From 7555ff3ad0f08b8e967411055a5990533fd2edf9 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Fri, 21 Aug 2015 19:48:47 +0900 Subject: [PATCH 05/13] allow preprocessing dictionary mapping before importing objects --- .../Importing Data/BaseDataTransaction+Importing.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CoreStore/Importing Data/BaseDataTransaction+Importing.swift b/CoreStore/Importing Data/BaseDataTransaction+Importing.swift index 2bb94ec..a5dddf5 100644 --- a/CoreStore/Importing Data/BaseDataTransaction+Importing.swift +++ b/CoreStore/Importing Data/BaseDataTransaction+Importing.swift @@ -174,7 +174,7 @@ public extension BaseDataTransaction { func importUniqueObjects( into: Into, sourceArray: [T.ImportSource], - preProcess: ((mapping: [T.UniqueIDType: T.ImportSource]) throws -> Void)? = nil) throws { + preProcess: ((inout mapping: [T.UniqueIDType: T.ImportSource]) throws -> Void)? = nil) throws { CoreStore.assert( self.bypassesQueueing || self.transactionQueue.isCurrentExecutionContext(), @@ -202,7 +202,7 @@ public extension BaseDataTransaction { try autoreleasepool { - try preProcess(mapping: mapping) + try preProcess(mapping: &mapping) } } @@ -230,7 +230,7 @@ public extension BaseDataTransaction { func importUniqueObjects( into: Into, sourceArray: [T.ImportSource], - preProcess: ((mapping: [T.UniqueIDType: T.ImportSource]) throws -> Void)? = nil, + preProcess: ((inout mapping: [T.UniqueIDType: T.ImportSource]) throws -> Void)? = nil, postProcess: (sorted: [T]) -> Void) throws { CoreStore.assert( @@ -261,7 +261,7 @@ public extension BaseDataTransaction { try autoreleasepool { - try preProcess(mapping: mapping) + try preProcess(mapping: &mapping) } } From 093c1d410fc4af749bae401d4e8a1637794131ca Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Sun, 23 Aug 2015 14:02:27 +0900 Subject: [PATCH 06/13] temporarily fix an Xcode 7 bug (still present as of beta 5) (temporarily fixes #12) --- CoreStore/Observing/ListMonitor.swift | 5 ++++- CoreStore/Observing/ObjectMonitor.swift | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CoreStore/Observing/ListMonitor.swift b/CoreStore/Observing/ListMonitor.swift index 3d3fef3..36a8b97 100644 --- a/CoreStore/Observing/ListMonitor.swift +++ b/CoreStore/Observing/ListMonitor.swift @@ -779,7 +779,7 @@ extension ListMonitor: FetchedResultsControllerHandler { ] ) - case .Move: + case .Move where indexPath != newIndexPath: NSNotificationCenter.defaultCenter().postNotificationName( ListMonitorDidMoveObjectNotification, object: self, @@ -789,6 +789,9 @@ extension ListMonitor: FetchedResultsControllerHandler { UserInfoKeyNewIndexPath: newIndexPath! ] ) + + default: + break } } diff --git a/CoreStore/Observing/ObjectMonitor.swift b/CoreStore/Observing/ObjectMonitor.swift index f06d257..f6f446d 100644 --- a/CoreStore/Observing/ObjectMonitor.swift +++ b/CoreStore/Observing/ObjectMonitor.swift @@ -179,7 +179,7 @@ public final class ObjectMonitor { let fetchRequest = NSFetchRequest() fetchRequest.entity = object.entity - fetchRequest.fetchLimit = 1 + fetchRequest.fetchLimit = 0 fetchRequest.resultType = .ManagedObjectResultType fetchRequest.sortDescriptors = [] @@ -288,7 +288,7 @@ extension ObjectMonitor: FetchedResultsControllerHandler { userInfo: [UserInfoKeyObject: anObject] ) - case .Update: + case .Update, .Move where indexPath == newIndexPath: NSNotificationCenter.defaultCenter().postNotificationName( ObjectMonitorDidUpdateObjectNotification, object: self, From 006d5e140262ff1b319d3e6788c291cc75ad3c70 Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Sun, 23 Aug 2015 14:15:48 +0900 Subject: [PATCH 07/13] rewrote ImportableObject protocol methods --- .../BaseDataTransaction+Importing.swift | 85 ++++++++++++++----- CoreStore/Observing/ObjectMonitor.swift | 4 +- 2 files changed, 65 insertions(+), 24 deletions(-) diff --git a/CoreStore/Importing Data/BaseDataTransaction+Importing.swift b/CoreStore/Importing Data/BaseDataTransaction+Importing.swift index a5dddf5..564a8c7 100644 --- a/CoreStore/Importing Data/BaseDataTransaction+Importing.swift +++ b/CoreStore/Importing Data/BaseDataTransaction+Importing.swift @@ -31,24 +31,17 @@ public protocol ImportableObject: class { typealias ImportSource - static func shouldImportFromSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) -> Bool + static func shouldInsertFromImportSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) -> Bool func didInsertFromImportSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) throws - - func updateFromImportSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) throws } public extension ImportableObject { - static func shouldImportFromSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) -> Bool { + static func shouldInsertFromImportSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) -> Bool { return true } - - func didInsertFromImportSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) throws { - - try self.updateFromImportSource(source, inTransaction: transaction) - } } @@ -60,7 +53,20 @@ public protocol ImportableUniqueObject: ImportableObject { var uniqueIDValue: UniqueIDType { get set } - static func uniqueIDFromImportSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) throws -> UniqueIDType + static func uniqueIDFromImportSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) throws -> UniqueIDType? + + static func shouldUpdateFromImportSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) -> Bool + + func updateFromImportSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) throws +} + + +public extension ImportableUniqueObject { + + func didInsertFromImportSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) throws { + + try self.updateFromImportSource(source, inTransaction: transaction) + } } @@ -77,7 +83,7 @@ public extension BaseDataTransaction { return try autoreleasepool { - if !T.shouldImportFromSource(source, inTransaction: self) { + guard T.shouldInsertFromImportSource(source, inTransaction: self) else { return nil } @@ -101,6 +107,11 @@ public extension BaseDataTransaction { for source in sourceArray { + guard T.shouldInsertFromImportSource(source, inTransaction: self) else { + + continue + } + try autoreleasepool { let object = self.create(into) @@ -125,6 +136,11 @@ public extension BaseDataTransaction { var objects = [T]() for source in sourceArray { + guard T.shouldInsertFromImportSource(source, inTransaction: self) else { + + continue + } + try autoreleasepool { let object = self.create(into) @@ -148,14 +164,12 @@ public extension BaseDataTransaction { return try autoreleasepool { - if !T.shouldImportFromSource(source, inTransaction: self) { + let uniqueIDKeyPath = T.uniqueIDKeyPath + guard let uniqueIDValue = try T.uniqueIDFromImportSource(source, inTransaction: self) else { return nil } - let uniqueIDKeyPath = T.uniqueIDKeyPath - let uniqueIDValue = try T.uniqueIDFromImportSource(source, inTransaction: self) - if let object = self.fetchOne(From(T), Where(uniqueIDKeyPath, isEqualTo: uniqueIDValue)) { try object.updateFromImportSource(source, inTransaction: self) @@ -163,6 +177,11 @@ public extension BaseDataTransaction { } else { + guard T.shouldInsertFromImportSource(source, inTransaction: self) else { + + return nil + } + let object = self.create(into) object.uniqueIDValue = uniqueIDValue try object.didInsertFromImportSource(source, inTransaction: self) @@ -188,12 +207,11 @@ public extension BaseDataTransaction { try autoreleasepool { - if !T.shouldImportFromSource(source, inTransaction: self) { + guard let uniqueIDValue = try T.uniqueIDFromImportSource(source, inTransaction: self) else { return } - let uniqueIDValue = try T.uniqueIDFromImportSource(source, inTransaction: self) mapping[uniqueIDValue] = source } } @@ -211,7 +229,14 @@ public extension BaseDataTransaction { try autoreleasepool { let uniqueIDValue = object.uniqueIDValue - try object.updateFromImportSource(mapping.removeValueForKey(uniqueIDValue)!, inTransaction: self) + + guard let source = mapping.removeValueForKey(uniqueIDValue) + where T.shouldUpdateFromImportSource(source, inTransaction: self) else { + + return + } + + try object.updateFromImportSource(source, inTransaction: self) } } @@ -219,6 +244,11 @@ public extension BaseDataTransaction { try autoreleasepool { + guard T.shouldInsertFromImportSource(source, inTransaction: self) else { + + return + } + let object = self.create(into) object.uniqueIDValue = uniqueIDValue try object.didInsertFromImportSource(source, inTransaction: self) @@ -246,12 +276,11 @@ public extension BaseDataTransaction { try autoreleasepool { - if !T.shouldImportFromSource(source, inTransaction: self) { + guard let uniqueIDValue = try T.uniqueIDFromImportSource(source, inTransaction: self) else { return } - - let uniqueIDValue = try T.uniqueIDFromImportSource(source, inTransaction: self) + mapping[uniqueIDValue] = source sortedIDs.append(uniqueIDValue) } @@ -271,7 +300,14 @@ public extension BaseDataTransaction { try autoreleasepool { let uniqueIDValue = object.uniqueIDValue - try object.updateFromImportSource(mapping.removeValueForKey(uniqueIDValue)!, inTransaction: self) + + guard let source = mapping.removeValueForKey(uniqueIDValue) + where T.shouldUpdateFromImportSource(source, inTransaction: self) else { + + return + } + + try object.updateFromImportSource(source, inTransaction: self) objects[uniqueIDValue] = object } } @@ -280,6 +316,11 @@ public extension BaseDataTransaction { try autoreleasepool { + guard T.shouldInsertFromImportSource(source, inTransaction: self) else { + + return + } + let object = self.create(into) object.uniqueIDValue = uniqueIDValue try object.didInsertFromImportSource(source, inTransaction: self) diff --git a/CoreStore/Observing/ObjectMonitor.swift b/CoreStore/Observing/ObjectMonitor.swift index f6f446d..6402a28 100644 --- a/CoreStore/Observing/ObjectMonitor.swift +++ b/CoreStore/Observing/ObjectMonitor.swift @@ -129,13 +129,13 @@ public final class ObjectMonitor { let previousCommitedAttributes = strongSelf.lastCommittedAttributes let currentCommitedAttributes = object.committedValuesForKeys(nil) as! [String: NSObject] - let changedKeys = currentCommitedAttributes.keys.reduce(Set()) { (var changedKeys, key) -> Set in + var changedKeys = Set() + for key in currentCommitedAttributes.keys { if previousCommitedAttributes[key] != currentCommitedAttributes[key] { changedKeys.insert(key) } - return changedKeys } strongSelf.lastCommittedAttributes = currentCommitedAttributes From 2f935de04a10e08d091dbf54fce92155cc1a34b0 Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Sun, 23 Aug 2015 14:02:27 +0900 Subject: [PATCH 08/13] temporarily fix an Xcode 7 bug (still present as of beta 5) (temporarily fixes #12) --- CoreStore/Observing/ListMonitor.swift | 5 ++++- CoreStore/Observing/ObjectMonitor.swift | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CoreStore/Observing/ListMonitor.swift b/CoreStore/Observing/ListMonitor.swift index 3d3fef3..36a8b97 100644 --- a/CoreStore/Observing/ListMonitor.swift +++ b/CoreStore/Observing/ListMonitor.swift @@ -779,7 +779,7 @@ extension ListMonitor: FetchedResultsControllerHandler { ] ) - case .Move: + case .Move where indexPath != newIndexPath: NSNotificationCenter.defaultCenter().postNotificationName( ListMonitorDidMoveObjectNotification, object: self, @@ -789,6 +789,9 @@ extension ListMonitor: FetchedResultsControllerHandler { UserInfoKeyNewIndexPath: newIndexPath! ] ) + + default: + break } } diff --git a/CoreStore/Observing/ObjectMonitor.swift b/CoreStore/Observing/ObjectMonitor.swift index f06d257..f6f446d 100644 --- a/CoreStore/Observing/ObjectMonitor.swift +++ b/CoreStore/Observing/ObjectMonitor.swift @@ -179,7 +179,7 @@ public final class ObjectMonitor { let fetchRequest = NSFetchRequest() fetchRequest.entity = object.entity - fetchRequest.fetchLimit = 1 + fetchRequest.fetchLimit = 0 fetchRequest.resultType = .ManagedObjectResultType fetchRequest.sortDescriptors = [] @@ -288,7 +288,7 @@ extension ObjectMonitor: FetchedResultsControllerHandler { userInfo: [UserInfoKeyObject: anObject] ) - case .Update: + case .Update, .Move where indexPath == newIndexPath: NSNotificationCenter.defaultCenter().postNotificationName( ObjectMonitorDidUpdateObjectNotification, object: self, From 682b13a8d362b67ef6bdfbea9ec372771135ed33 Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Sun, 23 Aug 2015 14:25:18 +0900 Subject: [PATCH 09/13] version bump --- CoreStore.podspec | 2 +- CoreStore/Info.plist | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CoreStore.podspec b/CoreStore.podspec index 17769c0..16792c5 100644 --- a/CoreStore.podspec +++ b/CoreStore.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "CoreStore" - s.version = "1.2.0" + s.version = "1.2.1" s.license = "MIT" s.summary = "Simple, elegant, and smart Core Data programming with Swift" s.homepage = "https://github.com/JohnEstropia/CoreStore" diff --git a/CoreStore/Info.plist b/CoreStore/Info.plist index 331a2da..ae2dbbb 100644 --- a/CoreStore/Info.plist +++ b/CoreStore/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.2.0 + 1.2.1 CFBundleSignature ???? CFBundleVersion From d3ffe7a8fc03816db2829968399c93703d3a3e51 Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Sun, 23 Aug 2015 14:37:21 +0900 Subject: [PATCH 10/13] add default implementation for souldUpdateFromImportSource --- CoreStore/Importing Data/BaseDataTransaction+Importing.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CoreStore/Importing Data/BaseDataTransaction+Importing.swift b/CoreStore/Importing Data/BaseDataTransaction+Importing.swift index 564a8c7..afd8ed7 100644 --- a/CoreStore/Importing Data/BaseDataTransaction+Importing.swift +++ b/CoreStore/Importing Data/BaseDataTransaction+Importing.swift @@ -63,6 +63,11 @@ public protocol ImportableUniqueObject: ImportableObject { public extension ImportableUniqueObject { + static func shouldUpdateFromImportSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) -> Bool { + + return true + } + func didInsertFromImportSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) throws { try self.updateFromImportSource(source, inTransaction: transaction) From 0c9e6afe0e88fc0cfff919b5ed30d213b7b1cfe7 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Mon, 24 Aug 2015 17:33:27 +0900 Subject: [PATCH 11/13] added utility to inspect NSEntityDescription for a given NSManagedObject type --- .../Internal/NSManagedObjectModel+Setup.swift | 2 +- CoreStore/Setting Up/DataStack.swift | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CoreStore/Internal/NSManagedObjectModel+Setup.swift b/CoreStore/Internal/NSManagedObjectModel+Setup.swift index 8ddd4b5..ffd82e2 100644 --- a/CoreStore/Internal/NSManagedObjectModel+Setup.swift +++ b/CoreStore/Internal/NSManagedObjectModel+Setup.swift @@ -150,7 +150,7 @@ internal extension NSManagedObjectModel { return self.entityNameMapping[NSStringFromClass(entityClass)]! } - @nonobjc internal func entityMapping() -> [String: NSManagedObject.Type] { + @nonobjc internal func entityTypesMapping() -> [String: NSManagedObject.Type] { return self.entityNameMapping.reduce([:]) { (var mapping, pair) in diff --git a/CoreStore/Setting Up/DataStack.swift b/CoreStore/Setting Up/DataStack.swift index e435c0a..46fe6ce 100644 --- a/CoreStore/Setting Up/DataStack.swift +++ b/CoreStore/Setting Up/DataStack.swift @@ -84,9 +84,20 @@ public final class DataStack { /** Returns the entity name-to-class type mapping from the `DataStack`'s model. */ - public var entitiesByName: [String: NSManagedObject.Type] { + public var entityTypesByName: [String: NSManagedObject.Type] { - return self.model.entityMapping() + return self.model.entityTypesMapping() + } + + /** + Returns the `NSEntityDescription` for the specified `NSManagedObject` subclass. + */ + public func entityDescriptionForType(type: NSManagedObject.Type) -> NSEntityDescription? { + + return NSEntityDescription.entityForName( + self.model.entityNameForClass(type), + inManagedObjectContext: self.mainContext + ) } /** From 8ed6a78609fae7f6a81600efe2661fa951b48c14 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Mon, 24 Aug 2015 17:36:40 +0900 Subject: [PATCH 12/13] CoreStore adapter method --- CoreStore/Setting Up/CoreStore+Setup.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CoreStore/Setting Up/CoreStore+Setup.swift b/CoreStore/Setting Up/CoreStore+Setup.swift index 11b42cf..c54c387 100644 --- a/CoreStore/Setting Up/CoreStore+Setup.swift +++ b/CoreStore/Setting Up/CoreStore+Setup.swift @@ -43,9 +43,17 @@ public extension CoreStore { /** Returns the entity name-to-class type mapping from the `defaultStack`'s model. */ - public static var entitiesByName: [String: NSManagedObject.Type] { + public static var entityTypesByName: [String: NSManagedObject.Type] { - return self.defaultStack.entitiesByName + return self.defaultStack.entityTypesByName + } + + /** + Returns the `NSEntityDescription` for the specified `NSManagedObject` subclass from `defaultStack`'s model. + */ + public static func entityDescriptionForType(type: NSManagedObject.Type) -> NSEntityDescription? { + + return self.defaultStack.entityDescriptionForType(type) } /** From d04b4ca0850eee18fd399d4830b33e962d0f9111 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Mon, 24 Aug 2015 20:40:19 +0900 Subject: [PATCH 13/13] added utility for ListMonitor to return the index/indexPath of a specified object --- CoreStore/Observing/ListMonitor.swift | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CoreStore/Observing/ListMonitor.swift b/CoreStore/Observing/ListMonitor.swift index 36a8b97..f6f5318 100644 --- a/CoreStore/Observing/ListMonitor.swift +++ b/CoreStore/Observing/ListMonitor.swift @@ -273,6 +273,28 @@ public final class ListMonitor { return sections[section] } + /** + Returns the index of the `NSManagedObject` if it exists in the `ListMonitor`'s fetched objects, or `nil` if not found. + + - parameter object: the `NSManagedObject` to search the index of + - returns: the index of the `NSManagedObject` if it exists in the `ListMonitor`'s fetched objects, or `nil` if not found. + */ + public func indexOf(object: T) -> Int? { + + return (self.fetchedResultsController.fetchedObjects as? [T] ?? []).indexOf(object) + } + + /** + Returns the `NSIndexPath` of the `NSManagedObject` if it exists in the `ListMonitor`'s fetched objects, or `nil` if not found. + + - parameter object: the `NSManagedObject` to search the index of + - returns: the `NSIndexPath` of the `NSManagedObject` if it exists in the `ListMonitor`'s fetched objects, or `nil` if not found. + */ + public func indexPathOf(object: T) -> NSIndexPath? { + + return self.fetchedResultsController.indexPathForObject(object) + } + /** Registers a `ListObserver` to be notified when changes to the receiver's list occur.