attempt sight improvement for the FRC bug workaround #20

This commit is contained in:
John Rommel Estropia
2015-10-23 00:40:38 +09:00
parent 9ca83d9c5d
commit dcfb09eda7
4 changed files with 50 additions and 54 deletions

View File

@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "CoreStore"
s.version = "1.3.1"
s.version = "1.3.2"
s.license = "MIT"
s.summary = "Simple, elegant, and smart Core Data programming with Swift"
s.homepage = "https://github.com/JohnEstropia/CoreStore"
@@ -8,6 +8,7 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/JohnEstropia/CoreStore.git", :tag => s.version.to_s }
s.ios.deployment_target = "8.0"
s.watchos.deployment_target = "2.0"
s.source_files = "CoreStore", "CoreStore/**/*.{swift}"
s.frameworks = "Foundation", "UIKit", "CoreData"

View File

@@ -29,7 +29,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2F03A53A19C5C6DA005002A5"
BuildableName = "CoreStoreTests iOS.xctest"
BuildableName = "CoreStoreTests.xctest"
BlueprintName = "CoreStoreTests iOS"
ReferencedContainer = "container:CoreStore.xcodeproj">
</BuildableReference>
@@ -47,7 +47,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2F03A53A19C5C6DA005002A5"
BuildableName = "CoreStoreTests iOS.xctest"
BuildableName = "CoreStoreTests.xctest"
BlueprintName = "CoreStoreTests iOS"
ReferencedContainer = "container:CoreStore.xcodeproj">
</BuildableReference>

View File

@@ -24,6 +24,7 @@
//
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
FOUNDATION_EXPORT double CoreStoreVersionNumber;
FOUNDATION_EXPORT const unsigned char CoreStoreVersionString[];

View File

@@ -99,9 +99,9 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
return
}
guard type.rawValue > 0 else {
guard let actualType = NSFetchedResultsChangeType(rawValue: type.rawValue) 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 iOS passes 0 for NSFetchedResultsChangeType, but this is not a valid enum case.
// Swift will then always execute the first case of the switch causing strange behaviour.
// https://forums.developer.apple.com/thread/12184#31850
return
@@ -112,54 +112,7 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
// https://forums.developer.apple.com/message/9998#9998
// 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 {
case .Move:
guard let indexPath = indexPath, let newIndexPath = newIndexPath else {
return
}
guard indexPath == newIndexPath else {
break
}
if self.deletedSections.contains(indexPath.indexAtPosition(0)) {
self.handler?.controller(
controller,
didChangeObject: anObject,
atIndexPath: nil,
forChangeType: .Insert,
newIndexPath: indexPath
)
return
}
switch actualType {
case .Update:
guard let section = indexPath?.indexAtPosition(0) else {
@@ -172,6 +125,47 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
return
}
case .Move:
guard let indexPath = indexPath, let newIndexPath = newIndexPath else {
return
}
guard indexPath == newIndexPath else {
break
}
if self.insertedSections.contains(indexPath.indexAtPosition(0)) {
// Observers that handle the .Move change are advised to delete then reinsert the object instead of just moving. This is especially true when indexPath and newIndexPath are equal. For example, calling tableView.moveRowAtIndexPath(_:toIndexPath) when both indexPaths are the same will crash the tableView.
self.handler?.controller(
controller,
didChangeObject: anObject,
atIndexPath: indexPath,
forChangeType: .Move,
newIndexPath: newIndexPath
)
return
}
if self.deletedSections.contains(indexPath.indexAtPosition(0)) {
self.handler?.controller(
controller,
didChangeObject: anObject,
atIndexPath: nil,
forChangeType: .Insert,
newIndexPath: indexPath
)
return
}
self.handler?.controller(
controller,
didChangeObject: anObject,
atIndexPath: indexPath,
forChangeType: .Update,
newIndexPath: nil
)
return
default:
break
}
@@ -180,7 +174,7 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
controller,
didChangeObject: anObject,
atIndexPath: indexPath,
forChangeType: type,
forChangeType: actualType,
newIndexPath: newIndexPath
)
}