Merge branch 'corestore2_develop' of github.com:JohnEstropia/CoreStore into corestore2_develop

This commit is contained in:
John Rommel Estropia
2016-06-11 19:10:12 +09:00
5 changed files with 42 additions and 44 deletions

View File

@@ -208,6 +208,11 @@ public extension NSFetchedResultsController {
applyFetchClauses: { fetchRequest in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
CoreStore.assert(
fetchRequest.sortDescriptors?.isEmpty == false,
"An \(cs_typeName(NSFetchedResultsController)) requires a sort information. Specify from a \(cs_typeName(OrderBy)) clause or any custom \(cs_typeName(FetchClause)) that provides a sort descriptor."
)
}
)
}

View File

@@ -56,10 +56,6 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
)
applyFetchClauses(fetchRequest: fetchRequest)
CoreStore.assert(
fetchRequest.sortDescriptors?.isEmpty == false,
"An \(cs_typeName(NSFetchedResultsController)) requires a sort information. Specify from a \(cs_typeName(OrderBy)) clause or any custom \(cs_typeName(FetchClause)) that provides a sort descriptor."
)
if let from = from {
self.reapplyAffectedStores = { fetchRequest, context in

View File

@@ -52,6 +52,11 @@ public extension NSFetchedResultsController {
applyFetchClauses: { fetchRequest in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
CoreStore.assert(
fetchRequest.sortDescriptors?.isEmpty == false,
"An \(cs_typeName(NSFetchedResultsController)) requires a sort information. Specify from a \(cs_typeName(CSOrderBy)) clause or any custom \(cs_typeName(CSFetchClause)) that provides a sort descriptor."
)
}
)
}

View File

@@ -85,6 +85,11 @@ public extension DataStack {
applyFetchClauses: { fetchRequest in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
CoreStore.assert(
fetchRequest.sortDescriptors?.isEmpty == false,
"An \(cs_typeName(NSFetchedResultsController)) requires a sort information. Specify from a \(cs_typeName(OrderBy)) clause or any custom \(cs_typeName(FetchClause)) that provides a sort descriptor."
)
}
)
}
@@ -121,6 +126,11 @@ public extension DataStack {
applyFetchClauses: { fetchRequest in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
CoreStore.assert(
fetchRequest.sortDescriptors?.isEmpty == false,
"An \(cs_typeName(NSFetchedResultsController)) requires a sort information. Specify from a \(cs_typeName(OrderBy)) clause or any custom \(cs_typeName(FetchClause)) that provides a sort descriptor."
)
},
createAsynchronously: createAsynchronously
)
@@ -163,6 +173,11 @@ public extension DataStack {
applyFetchClauses: { fetchRequest in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
CoreStore.assert(
fetchRequest.sortDescriptors?.isEmpty == false,
"An \(cs_typeName(NSFetchedResultsController)) requires a sort information. Specify from a \(cs_typeName(OrderBy)) clause or any custom \(cs_typeName(FetchClause)) that provides a sort descriptor."
)
}
)
}
@@ -202,6 +217,11 @@ public extension DataStack {
applyFetchClauses: { fetchRequest in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
CoreStore.assert(
fetchRequest.sortDescriptors?.isEmpty == false,
"An \(cs_typeName(NSFetchedResultsController)) requires a sort information. Specify from a \(cs_typeName(OrderBy)) clause or any custom \(cs_typeName(FetchClause)) that provides a sort descriptor."
)
},
createAsynchronously: createAsynchronously
)

View File

@@ -117,23 +117,15 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
*/
public subscript(safeSectionIndex sectionIndex: Int, safeItemIndex itemIndex: Int) -> T? {
CoreStore.assert(
!self.isPendingRefetch || NSThread.isMainThread(),
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
)
guard let sections = self.fetchedResultsController.sections
where sectionIndex < sections.count else {
return nil
}
let section = sections[sectionIndex]
guard itemIndex < section.numberOfObjects else {
guard let section = self.sectionInfoAtIndex(safeSectionIndex: sectionIndex) else {
return nil
}
return sections[sectionIndex].objects?[itemIndex] as? T
guard itemIndex >= 0 && itemIndex < section.numberOfObjects else {
return nil
}
return section.objects?[itemIndex] as? T
}
/**
@@ -148,7 +140,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
!self.isPendingRefetch || NSThread.isMainThread(),
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
)
return self.fetchedResultsController.objectAtIndexPath(indexPath) as! T
}
@@ -201,7 +192,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
!self.isPendingRefetch || NSThread.isMainThread(),
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
)
return (self.fetchedResultsController.fetchedObjects as? [T]) ?? []
}
@@ -214,12 +204,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
@warn_unused_result
public func objectsInSection(section: Int) -> [T] {
CoreStore.assert(
!self.isPendingRefetch || NSThread.isMainThread(),
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
)
return (self.fetchedResultsController.sections?[section].objects as? [T]) ?? []
return (self.sectionInfoAtIndex(section).objects as? [T]) ?? []
}
/**
@@ -231,12 +216,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
@warn_unused_result
public func objectsInSection(safeSectionIndex section: Int) -> [T]? {
CoreStore.assert(
!self.isPendingRefetch || NSThread.isMainThread(),
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
)
return (self.fetchedResultsController.sections?[section].objects as? [T]) ?? []
return (self.sectionInfoAtIndex(safeSectionIndex: section)?.objects as? [T]) ?? []
}
/**
@@ -251,7 +231,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
!self.isPendingRefetch || NSThread.isMainThread(),
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
)
return self.fetchedResultsController.sections?.count ?? 0
}
@@ -267,7 +246,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
!self.isPendingRefetch || NSThread.isMainThread(),
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
)
return self.fetchedResultsController.fetchedObjects?.count ?? 0
}
@@ -308,7 +286,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
!self.isPendingRefetch || NSThread.isMainThread(),
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
)
return self.fetchedResultsController.sections![section]
}
@@ -325,13 +302,15 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
!self.isPendingRefetch || NSThread.isMainThread(),
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
)
guard section >= 0 else {
return nil
}
guard let sections = self.fetchedResultsController.sections
where section < sections.count else {
return nil
}
return sections[section]
}
@@ -347,7 +326,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
!self.isPendingRefetch || NSThread.isMainThread(),
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
)
return self.fetchedResultsController.sections ?? []
}
@@ -365,7 +343,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
!self.isPendingRefetch || NSThread.isMainThread(),
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
)
return self.fetchedResultsController.sectionForSectionIndexTitle(title, atIndex: index)
}
@@ -381,7 +358,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
!self.isPendingRefetch || NSThread.isMainThread(),
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
)
return self.fetchedResultsController.sectionIndexTitles
}
@@ -398,7 +374,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
!self.isPendingRefetch || NSThread.isMainThread(),
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
)
return (self.fetchedResultsController.fetchedObjects as? [T] ?? []).indexOf(object)
}
@@ -415,7 +390,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
!self.isPendingRefetch || NSThread.isMainThread(),
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
)
return self.fetchedResultsController.indexPathForObject(object)
}
@@ -767,7 +741,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
NSThread.isMainThread(),
"Attempted to add an observer of type \(cs_typeName(observer)) outside the main thread."
)
self.registerChangeNotification(
&self.willChangeListKey,
name: ListMonitorWillChangeListNotification,
@@ -955,7 +928,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
NSThread.isMainThread(),
"Attempted to remove an observer of type \(cs_typeName(observer)) outside the main thread."
)
let nilValue: AnyObject? = nil
cs_setAssociatedRetainedObject(nilValue, forKey: &self.willChangeListKey, inObject: observer)
cs_setAssociatedRetainedObject(nilValue, forKey: &self.didChangeListKey, inObject: observer)