improved migrationchain validation

This commit is contained in:
John Rommel Estropia
2015-07-13 07:47:43 +09:00
parent a64bcc474e
commit f99349f99d
9 changed files with 89 additions and 41 deletions

View File

@@ -78,6 +78,10 @@ public extension DataStack {
NSThread.isMainThread(),
"Attempted to observe objects from \(typeName(self)) outside the main thread."
)
CoreStore.assert(
fetchClauses.filter { $0 is OrderBy }.count > 0,
"A ListMonitor requires an OrderBy clause."
)
return ListMonitor(
dataStack: self,
@@ -114,6 +118,10 @@ public extension DataStack {
NSThread.isMainThread(),
"Attempted to observe objects from \(typeName(self)) outside the main thread."
)
CoreStore.assert(
fetchClauses.filter { $0 is OrderBy }.count > 0,
"A ListMonitor requires an OrderBy clause."
)
return ListMonitor(
dataStack: self,

View File

@@ -500,21 +500,9 @@ public final class ListMonitor<T: NSManagedObject> {
self.sectionIndexTransformer = { $0 }
}
fetchedResultsControllerDelegate.handler = self
fetchedResultsControllerDelegate.fetchedResultsController = fetchedResultsController
do {
try fetchedResultsController.performFetch()
}
catch {
CoreStore.handleError(
error as NSError,
"Failed to perform fetch on \(typeName(NSFetchedResultsController))."
)
}
try! fetchedResultsController.performFetch()
}

View File

@@ -202,19 +202,7 @@ public final class ObjectMonitor<T: NSManagedObject> {
fetchedResultsControllerDelegate.handler = self
fetchedResultsControllerDelegate.fetchedResultsController = fetchedResultsController
do {
try fetchedResultsController.performFetch()
}
catch {
CoreStore.handleError(
error as NSError,
"Failed to perform fetch for \(typeName(NSFetchedResultsController))."
)
}
try! fetchedResultsController.performFetch()
self.lastCommittedAttributes = (self.object?.committedValuesForKeys(nil) as? [String: NSObject]) ?? [:]
}