mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-19 07:27:02 +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
|
||||
}
|
||||
|
||||
@@ -756,20 +756,19 @@ public extension DataStack {
|
||||
let fileURL = storage.fileURL
|
||||
|
||||
let temporaryDirectoryURL = NSURL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
|
||||
.URLByAppendingPathComponent(NSBundle.mainBundle().bundleIdentifier ?? "com.CoreStore.DataStack")
|
||||
.URLByAppendingPathComponent(NSBundle.mainBundle().bundleIdentifier ?? "com.CoreStore.DataStack")!
|
||||
.URLByAppendingPathComponent(NSProcessInfo().globallyUniqueString)
|
||||
|
||||
let fileManager = NSFileManager.defaultManager()
|
||||
try! fileManager.createDirectoryAtURL(
|
||||
temporaryDirectoryURL,
|
||||
temporaryDirectoryURL!,
|
||||
withIntermediateDirectories: true,
|
||||
attributes: nil
|
||||
)
|
||||
|
||||
let temporaryFileURL = temporaryDirectoryURL.URLByAppendingPathComponent(
|
||||
let temporaryFileURL = temporaryDirectoryURL!.URLByAppendingPathComponent(
|
||||
fileURL.lastPathComponent!,
|
||||
isDirectory: false
|
||||
)
|
||||
isDirectory: false)!
|
||||
|
||||
let migrationManager = MigrationManager(
|
||||
sourceModel: sourceModel,
|
||||
|
||||
@@ -65,8 +65,7 @@ public final class LegacySQLiteStore: LocalStorage, DefaultInitializableStore {
|
||||
|
||||
self.fileURL = LegacySQLiteStore.defaultRootDirectory.URLByAppendingPathComponent(
|
||||
fileName,
|
||||
isDirectory: false
|
||||
)
|
||||
isDirectory: false)!
|
||||
self.configuration = configuration
|
||||
self.mappingModelBundles = mappingModelBundles
|
||||
self.localStorageOptions = localStorageOptions
|
||||
@@ -210,8 +209,8 @@ public final class LegacySQLiteStore: LocalStorage, DefaultInitializableStore {
|
||||
}()
|
||||
|
||||
internal static let defaultFileURL = LegacySQLiteStore.defaultRootDirectory
|
||||
.URLByAppendingPathComponent(DataStack.applicationName, isDirectory: false)
|
||||
.URLByAppendingPathExtension("sqlite")
|
||||
.URLByAppendingPathComponent(DataStack.applicationName, isDirectory: false)!
|
||||
.URLByAppendingPathExtension("sqlite")!
|
||||
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@@ -63,7 +63,7 @@ public final class SQLiteStore: LocalStorage, DefaultInitializableStore {
|
||||
public init(fileName: String, configuration: String? = nil, mappingModelBundles: [NSBundle] = NSBundle.allBundles(), localStorageOptions: LocalStorageOptions = nil) {
|
||||
|
||||
self.fileURL = SQLiteStore.defaultRootDirectory
|
||||
.URLByAppendingPathComponent(fileName, isDirectory: false)
|
||||
.URLByAppendingPathComponent(fileName, isDirectory: false)!
|
||||
self.configuration = configuration
|
||||
self.mappingModelBundles = mappingModelBundles
|
||||
self.localStorageOptions = localStorageOptions
|
||||
@@ -79,7 +79,7 @@ public final class SQLiteStore: LocalStorage, DefaultInitializableStore {
|
||||
*/
|
||||
public init() {
|
||||
|
||||
self.fileURL = SQLiteStore.defaultFileURL
|
||||
self.fileURL = SQLiteStore.defaultFileURL!
|
||||
self.configuration = nil
|
||||
self.mappingModelBundles = NSBundle.allBundles()
|
||||
self.localStorageOptions = nil
|
||||
@@ -206,15 +206,13 @@ public final class SQLiteStore: LocalStorage, DefaultInitializableStore {
|
||||
|
||||
return defaultSystemDirectory.URLByAppendingPathComponent(
|
||||
NSBundle.mainBundle().bundleIdentifier ?? "com.CoreStore.DataStack",
|
||||
isDirectory: true
|
||||
)
|
||||
isDirectory: true)!
|
||||
}()
|
||||
|
||||
internal static let defaultFileURL = SQLiteStore.defaultRootDirectory
|
||||
.URLByAppendingPathComponent(
|
||||
(NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleName") as? String) ?? "CoreData",
|
||||
isDirectory: false
|
||||
)
|
||||
isDirectory: false)!
|
||||
.URLByAppendingPathExtension("sqlite")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user