Magical NSFetchedResultsController bugfix....

This commit is contained in:
John Estropia
2016-09-09 12:49:10 +09:00
parent 82de482191
commit 3f28198552
19 changed files with 150 additions and 158 deletions

View File

@@ -45,9 +45,18 @@ internal final class CoreStoreFetchRequest<T: NSFetchRequestResult>: NSFetchRequ
// MARK: NSFetchRequest
@objc
override var affectedStores: [NSPersistentStore]? {
dynamic override var affectedStores: [NSPersistentStore]? {
get { return super.affectedStores }
set { super.affectedStores = newValue }
get {
return super.affectedStores
// let affectedStores: NSArray? = super.affectedStores.flatMap({ NSArray(array: $0) } )
// return affectedStores as? [NSPersistentStore]
}
set {
super.affectedStores = newValue
// super.affectedStores = newValue.flatMap(Array.init)
}
}
}

View File

@@ -30,9 +30,10 @@ import Foundation
internal extension DispatchQueue {
internal convenience init(serialWith label: String, qos: DispatchQoS = .default) {
@nonobjc
internal static func serial(_ label: String, qos: DispatchQoS = .default) -> DispatchQueue {
self.init(
return DispatchQueue(
label: label,
qos: qos,
attributes: [],
@@ -41,9 +42,10 @@ internal extension DispatchQueue {
)
}
internal convenience init(concurrentWith label: String, qos: DispatchQoS = .default) {
@nonobjc
internal static func concurrent(_ label: String, qos: DispatchQoS = .default) -> DispatchQueue {
self.init(
return DispatchQueue(
label: label,
qos: qos,
attributes: .concurrent,
@@ -52,6 +54,7 @@ internal extension DispatchQueue {
)
}
@nonobjc
internal func cs_isCurrentExecutionContext() -> Bool {
let specific = ObjectIdentifier(self)
@@ -60,21 +63,25 @@ internal extension DispatchQueue {
return DispatchQueue.getSpecific(key: Static.specificKey) == specific
}
@nonobjc
internal func cs_sync<T>(_ closure: () throws -> T) rethrows -> T {
return try self.sync { try autoreleasepool(invoking: closure) }
}
@nonobjc
internal func cs_async(_ closure: @escaping () -> Void) {
self.async { autoreleasepool(invoking: closure) }
}
@nonobjc
internal func cs_barrierSync<T>(_ closure: () throws -> T) rethrows -> T {
return try self.sync(flags: .barrier) { try autoreleasepool(invoking: closure) }
}
@nonobjc
internal func cs_barrierAsync(_ closure: @escaping () -> Void) {
self.async(flags: .barrier) { autoreleasepool(invoking: closure) }

View File

@@ -108,7 +108,7 @@ internal final class FetchedResultsControllerDelegate<EntityType: NSManagedObjec
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.
@@ -123,19 +123,12 @@ internal final class FetchedResultsControllerDelegate<EntityType: NSManagedObjec
if #available(iOS 10.0, tvOS 10.0, watchOS 3.0, *) {
// iOS 10 is better, but still not perfect...
// I don't know if iOS 10 even attempted to fix this mess...
if case .update = actualType,
let indexPath = indexPath,
let newIndexPath = newIndexPath {
indexPath != nil,
newIndexPath != nil {
self.handler?.controller(
controller,
didChangeObject: anObject,
atIndexPath: indexPath,
forChangeType: .move,
newIndexPath: newIndexPath
)
return
actualType = .move
}
}

View File

@@ -147,7 +147,7 @@ internal extension NSManagedObjectContext {
}
@nonobjc
internal func saveAsynchronouslyWithCompletion(_ completion: ((_ result: SaveResult) -> Void) = { _ in }) {
internal func saveAsynchronouslyWithCompletion(_ completion: @escaping ((_ result: SaveResult) -> Void) = { _ in }) {
self.perform {

View File

@@ -34,7 +34,7 @@ internal final class NotificationObserver {
let observer: NSObjectProtocol
init(notificationName: Notification.Name, object: AnyObject?, queue: OperationQueue? = nil, closure: @escaping (_ note: Notification) -> Void) {
init(notificationName: Notification.Name, object: Any?, queue: OperationQueue? = nil, closure: @escaping (_ note: Notification) -> Void) {
self.observer = NotificationCenter.default.addObserver(
forName: notificationName,