diff --git a/CoreStore.podspec b/CoreStore.podspec index d78bfca..cbd4202 100644 --- a/CoreStore.podspec +++ b/CoreStore.podspec @@ -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" diff --git a/CoreStore.xcodeproj/xcshareddata/xcschemes/CoreStore iOS.xcscheme b/CoreStore.xcodeproj/xcshareddata/xcschemes/CoreStore iOS.xcscheme index 0d6020b..aa7e152 100644 --- a/CoreStore.xcodeproj/xcshareddata/xcschemes/CoreStore iOS.xcscheme +++ b/CoreStore.xcodeproj/xcshareddata/xcschemes/CoreStore iOS.xcscheme @@ -29,7 +29,7 @@ @@ -47,7 +47,7 @@ diff --git a/CoreStore/CoreStore.h b/CoreStore/CoreStore.h index a8d74f2..c3481e7 100644 --- a/CoreStore/CoreStore.h +++ b/CoreStore/CoreStore.h @@ -24,6 +24,7 @@ // #import +#import FOUNDATION_EXPORT double CoreStoreVersionNumber; FOUNDATION_EXPORT const unsigned char CoreStoreVersionString[]; diff --git a/CoreStore/Internal/FetchedResultsControllerDelegate.swift b/CoreStore/Internal/FetchedResultsControllerDelegate.swift index 2f01636..8eab6ac 100644 --- a/CoreStore/Internal/FetchedResultsControllerDelegate.swift +++ b/CoreStore/Internal/FetchedResultsControllerDelegate.swift @@ -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 ) }