mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-24 10:21:17 +01:00
working for Swift 2.3!
This commit is contained in:
@@ -108,7 +108,7 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
|
||||
return
|
||||
}
|
||||
|
||||
guard let actualType = NSFetchedResultsChangeType(rawValue: type.rawValue) else {
|
||||
guard var actualType = NSFetchedResultsChangeType(rawValue: type.rawValue) else {
|
||||
|
||||
// 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.
|
||||
@@ -121,6 +121,16 @@ 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 10.0, tvOS 10.0, watchOS 3.0, *) {
|
||||
|
||||
// I don't know if iOS 10 even attempted to fix this mess...
|
||||
if case .Update = actualType
|
||||
where indexPath != nil && newIndexPath != nil {
|
||||
|
||||
actualType = .Move
|
||||
}
|
||||
}
|
||||
|
||||
switch actualType {
|
||||
|
||||
case .Update:
|
||||
@@ -130,8 +140,8 @@ internal final class FetchedResultsControllerDelegate: NSObject, NSFetchedResult
|
||||
}
|
||||
if self.deletedSections.contains(section)
|
||||
|| self.insertedSections.contains(section) {
|
||||
|
||||
return
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
case .Move:
|
||||
|
||||
@@ -205,15 +205,22 @@ internal extension NSManagedObjectContext {
|
||||
internal func fetchCount(fetchRequest: NSFetchRequest) -> Int? {
|
||||
|
||||
var count = 0
|
||||
var error: NSError?
|
||||
var countError: ErrorType?
|
||||
self.performBlockAndWait {
|
||||
|
||||
count = self.countForFetchRequest(fetchRequest, error: &error)
|
||||
do {
|
||||
|
||||
count = try self.countForFetchRequest(fetchRequest)
|
||||
}
|
||||
catch {
|
||||
|
||||
countError = error
|
||||
}
|
||||
}
|
||||
if count == NSNotFound {
|
||||
|
||||
CoreStore.log(
|
||||
CoreStoreError(error),
|
||||
CoreStoreError(countError),
|
||||
"Failed executing fetch request."
|
||||
)
|
||||
return nil
|
||||
|
||||
@@ -42,7 +42,7 @@ internal extension NSManagedObjectModel {
|
||||
}
|
||||
|
||||
let modelFileURL = NSURL(fileURLWithPath: modelFilePath)
|
||||
let versionInfoPlistURL = modelFileURL.URLByAppendingPathComponent("VersionInfo.plist", isDirectory: false)
|
||||
let versionInfoPlistURL = modelFileURL.URLByAppendingPathComponent("VersionInfo.plist", isDirectory: false)!
|
||||
|
||||
guard let versionInfo = NSDictionary(contentsOfURL: versionInfoPlistURL),
|
||||
let versionHashes = versionInfo["NSManagedObjectModel_VersionHashes"] as? [String: AnyObject] else {
|
||||
@@ -83,7 +83,7 @@ internal extension NSManagedObjectModel {
|
||||
var modelVersionFileURL: NSURL?
|
||||
for modelVersion in modelVersions {
|
||||
|
||||
let fileURL = modelFileURL.URLByAppendingPathComponent("\(modelVersion).mom", isDirectory: false)
|
||||
let fileURL = modelFileURL.URLByAppendingPathComponent("\(modelVersion).mom", isDirectory: false)!
|
||||
|
||||
if modelVersion == currentModelVersion {
|
||||
|
||||
@@ -190,7 +190,7 @@ internal extension NSManagedObjectModel {
|
||||
}
|
||||
|
||||
let versionModelFileURL = modelFileURL.URLByAppendingPathComponent("\(modelVersion).mom", isDirectory: false)
|
||||
guard let model = NSManagedObjectModel(contentsOfURL: versionModelFileURL) else {
|
||||
guard let model = NSManagedObjectModel(contentsOfURL: versionModelFileURL!) else {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user