mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-26 19:31:29 +01:00
Merge branch 'corestore2_develop' of https://github.com/JohnEstropia/CoreStore into corestore2_develop
# Conflicts: # Sources/Observing/ListMonitor.swift
This commit is contained in:
@@ -117,25 +117,15 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
|||||||
*/
|
*/
|
||||||
public subscript(safeSectionIndex sectionIndex: Int, safeItemIndex itemIndex: Int) -> T? {
|
public subscript(safeSectionIndex sectionIndex: Int, safeItemIndex itemIndex: Int) -> T? {
|
||||||
|
|
||||||
CoreStore.assert(
|
guard let section = self.sectionInfoAtIndex(safeSectionIndex: sectionIndex) else {
|
||||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
|
||||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
|
||||||
)
|
|
||||||
guard sectionIndex >= 0 && itemIndex >= 0 else {
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
guard let sections = self.fetchedResultsController.sections
|
guard itemIndex >= 0 && itemIndex < section.numberOfObjects else {
|
||||||
where sectionIndex < sections.count else {
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
let section = sections[sectionIndex]
|
|
||||||
guard itemIndex < section.numberOfObjects else {
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return sections[sectionIndex].objects?[itemIndex] as? T
|
return section.objects?[itemIndex] as? T
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,7 +140,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
|||||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.fetchedResultsController.objectAtIndexPath(indexPath) as! T
|
return self.fetchedResultsController.objectAtIndexPath(indexPath) as! T
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +192,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
|||||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||||
)
|
)
|
||||||
|
|
||||||
return (self.fetchedResultsController.fetchedObjects as? [T]) ?? []
|
return (self.fetchedResultsController.fetchedObjects as? [T]) ?? []
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,12 +204,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
|||||||
@warn_unused_result
|
@warn_unused_result
|
||||||
public func objectsInSection(section: Int) -> [T] {
|
public func objectsInSection(section: Int) -> [T] {
|
||||||
|
|
||||||
CoreStore.assert(
|
return (self.sectionInfoAtIndex(section).objects as? [T]) ?? []
|
||||||
!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]) ?? []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -233,12 +216,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
|||||||
@warn_unused_result
|
@warn_unused_result
|
||||||
public func objectsInSection(safeSectionIndex section: Int) -> [T]? {
|
public func objectsInSection(safeSectionIndex section: Int) -> [T]? {
|
||||||
|
|
||||||
CoreStore.assert(
|
return (self.sectionInfoAtIndex(safeSectionIndex: section)?.objects as? [T]) ?? []
|
||||||
!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]) ?? []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -253,7 +231,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
|||||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.fetchedResultsController.sections?.count ?? 0
|
return self.fetchedResultsController.sections?.count ?? 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,7 +246,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
|||||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.fetchedResultsController.fetchedObjects?.count ?? 0
|
return self.fetchedResultsController.fetchedObjects?.count ?? 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,7 +286,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
|||||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.fetchedResultsController.sections![section]
|
return self.fetchedResultsController.sections![section]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,13 +302,15 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
|||||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
"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
|
guard let sections = self.fetchedResultsController.sections
|
||||||
where section < sections.count else {
|
where section < sections.count else {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return sections[section]
|
return sections[section]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,7 +326,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
|||||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.fetchedResultsController.sections ?? []
|
return self.fetchedResultsController.sections ?? []
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,7 +343,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
|||||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.fetchedResultsController.sectionForSectionIndexTitle(title, atIndex: index)
|
return self.fetchedResultsController.sectionForSectionIndexTitle(title, atIndex: index)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,7 +358,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
|||||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.fetchedResultsController.sectionIndexTitles
|
return self.fetchedResultsController.sectionIndexTitles
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,7 +374,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
|||||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
"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)
|
return (self.fetchedResultsController.fetchedObjects as? [T] ?? []).indexOf(object)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -417,7 +390,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
|||||||
!self.isPendingRefetch || NSThread.isMainThread(),
|
!self.isPendingRefetch || NSThread.isMainThread(),
|
||||||
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
"Attempted to access a \(cs_typeName(self)) outside the main thread while a refetch is in progress."
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.fetchedResultsController.indexPathForObject(object)
|
return self.fetchedResultsController.indexPathForObject(object)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -769,7 +741,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
|||||||
NSThread.isMainThread(),
|
NSThread.isMainThread(),
|
||||||
"Attempted to add an observer of type \(cs_typeName(observer)) outside the main thread."
|
"Attempted to add an observer of type \(cs_typeName(observer)) outside the main thread."
|
||||||
)
|
)
|
||||||
|
|
||||||
self.registerChangeNotification(
|
self.registerChangeNotification(
|
||||||
&self.willChangeListKey,
|
&self.willChangeListKey,
|
||||||
name: ListMonitorWillChangeListNotification,
|
name: ListMonitorWillChangeListNotification,
|
||||||
@@ -957,7 +928,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
|||||||
NSThread.isMainThread(),
|
NSThread.isMainThread(),
|
||||||
"Attempted to remove an observer of type \(cs_typeName(observer)) outside the main thread."
|
"Attempted to remove an observer of type \(cs_typeName(observer)) outside the main thread."
|
||||||
)
|
)
|
||||||
|
|
||||||
let nilValue: AnyObject? = nil
|
let nilValue: AnyObject? = nil
|
||||||
cs_setAssociatedRetainedObject(nilValue, forKey: &self.willChangeListKey, inObject: observer)
|
cs_setAssociatedRetainedObject(nilValue, forKey: &self.willChangeListKey, inObject: observer)
|
||||||
cs_setAssociatedRetainedObject(nilValue, forKey: &self.didChangeListKey, inObject: observer)
|
cs_setAssociatedRetainedObject(nilValue, forKey: &self.didChangeListKey, inObject: observer)
|
||||||
|
|||||||
Reference in New Issue
Block a user