mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-24 18:31:17 +01:00
fix section index titles when refetching a listMonitor
This commit is contained in:
@@ -49,6 +49,8 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
|
|||||||
|
|
||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|
||||||
|
internal var enabled = true
|
||||||
|
|
||||||
internal weak var handler: FetchedResultsControllerHandler?
|
internal weak var handler: FetchedResultsControllerHandler?
|
||||||
internal weak var fetchedResultsController: NSFetchedResultsController? {
|
internal weak var fetchedResultsController: NSFetchedResultsController? {
|
||||||
|
|
||||||
@@ -69,6 +71,11 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
|
|||||||
|
|
||||||
@objc dynamic func controllerWillChangeContent(controller: NSFetchedResultsController) {
|
@objc dynamic func controllerWillChangeContent(controller: NSFetchedResultsController) {
|
||||||
|
|
||||||
|
guard self.enabled else {
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
self.deletedSections = []
|
self.deletedSections = []
|
||||||
self.insertedSections = []
|
self.insertedSections = []
|
||||||
|
|
||||||
@@ -77,11 +84,21 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
|
|||||||
|
|
||||||
@objc dynamic func controllerDidChangeContent(controller: NSFetchedResultsController) {
|
@objc dynamic func controllerDidChangeContent(controller: NSFetchedResultsController) {
|
||||||
|
|
||||||
|
guard self.enabled else {
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
self.handler?.controllerDidChangeContent(controller)
|
self.handler?.controllerDidChangeContent(controller)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc dynamic func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
|
@objc dynamic func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
|
||||||
|
|
||||||
|
guard self.enabled else {
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
guard type.rawValue > 0 else {
|
guard type.rawValue > 0 else {
|
||||||
|
|
||||||
// This fix is for a bug where Apple passes 0 for NSFetchedResultsChangeType, but this is not a valid enum case.
|
// This fix is for a bug where Apple passes 0 for NSFetchedResultsChangeType, but this is not a valid enum case.
|
||||||
@@ -170,6 +187,11 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
|
|||||||
|
|
||||||
@objc dynamic func controller(controller: NSFetchedResultsController, didChangeSection sectionInfo: NSFetchedResultsSectionInfo, atIndex sectionIndex: Int, forChangeType type: NSFetchedResultsChangeType) {
|
@objc dynamic func controller(controller: NSFetchedResultsController, didChangeSection sectionInfo: NSFetchedResultsSectionInfo, atIndex sectionIndex: Int, forChangeType type: NSFetchedResultsChangeType) {
|
||||||
|
|
||||||
|
guard self.enabled else {
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
switch type {
|
switch type {
|
||||||
|
|
||||||
case .Delete: self.deletedSections.insert(sectionIndex)
|
case .Delete: self.deletedSections.insert(sectionIndex)
|
||||||
|
|||||||
@@ -840,7 +840,7 @@ public final class ListMonitor<T: NSManagedObject> {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
strongSelf.fetchedResultsControllerDelegate.fetchedResultsController = nil
|
strongSelf.fetchedResultsControllerDelegate.enabled = false
|
||||||
|
|
||||||
let fetchRequest = strongSelf.fetchedResultsController.fetchRequest
|
let fetchRequest = strongSelf.fetchedResultsController.fetchRequest
|
||||||
for clause in fetchClauses {
|
for clause in fetchClauses {
|
||||||
@@ -864,7 +864,7 @@ public final class ListMonitor<T: NSManagedObject> {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
strongSelf.fetchedResultsControllerDelegate.fetchedResultsController = strongSelf.fetchedResultsController
|
strongSelf.fetchedResultsControllerDelegate.enabled = true
|
||||||
strongSelf.isPendingRefetch = false
|
strongSelf.isPendingRefetch = false
|
||||||
|
|
||||||
NSNotificationCenter.defaultCenter().postNotificationName(
|
NSNotificationCenter.defaultCenter().postNotificationName(
|
||||||
|
|||||||
Reference in New Issue
Block a user