Workaround for Xcode 7.0.1+iOS 9 FRC bug

This commit is contained in:
John Estropia
2015-09-30 11:41:27 +09:00
parent cf9af6eef5
commit d89319d324

View File

@@ -82,22 +82,37 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
@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?) {
if #available(iOS 9, *) { // This whole dance is a workaround for a nasty bug introduced in XCode 7 targeted at iOS 8 devices
self.handler?.controller(
controller,
didChangeObject: anObject,
atIndexPath: indexPath,
forChangeType: type,
newIndexPath: newIndexPath
)
return
}
// Workaround a nasty bug introduced in XCode 7 targeted at iOS 8 devices
// http://stackoverflow.com/questions/31383760/ios-9-attempt-to-delete-and-reload-the-same-index-path/31384014#31384014 // http://stackoverflow.com/questions/31383760/ios-9-attempt-to-delete-and-reload-the-same-index-path/31384014#31384014
// https://forums.developer.apple.com/message/9998#9998 // https://forums.developer.apple.com/message/9998#9998
// https://forums.developer.apple.com/message/31849#31849 // https://forums.developer.apple.com/message/31849#31849
if #available(iOS 9, *) {
// Aaand XCode 7.0.1 now also bugs iOS 9 devices.. ughh
if case .Move = type where indexPath == newIndexPath {
self.handler?.controller(
controller,
didChangeObject: anObject,
atIndexPath: indexPath,
forChangeType: .Update,
newIndexPath: nil
)
}
else {
self.handler?.controller(
controller,
didChangeObject: anObject,
atIndexPath: indexPath,
forChangeType: type,
newIndexPath: newIndexPath
)
}
return
}
switch type { switch type {
case .Move: case .Move:
@@ -105,17 +120,20 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
return return
} }
if indexPath == newIndexPath guard indexPath == newIndexPath else {
&& self.deletedSections.contains(indexPath.section) {
break
self.handler?.controller( }
controller, if self.deletedSections.contains(indexPath.section) {
didChangeObject: anObject,
atIndexPath: nil, self.handler?.controller(
forChangeType: .Insert, controller,
newIndexPath: indexPath didChangeObject: anObject,
) atIndexPath: nil,
return forChangeType: .Insert,
newIndexPath: indexPath
)
return
} }
case .Update: case .Update: