mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-23 09:51:30 +01:00
tidy up
This commit is contained in:
@@ -321,10 +321,11 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak observer] (monitor) -> Void in
|
||||
|
||||
if let observer = observer {
|
||||
guard let observer = observer else {
|
||||
|
||||
observer.listMonitorWillChange(monitor)
|
||||
return
|
||||
}
|
||||
observer.listMonitorWillChange(monitor)
|
||||
}
|
||||
)
|
||||
self.registerChangeNotification(
|
||||
@@ -333,10 +334,11 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak observer] (monitor) -> Void in
|
||||
|
||||
if let observer = observer {
|
||||
guard let observer = observer else {
|
||||
|
||||
observer.listMonitorDidChange(monitor)
|
||||
return
|
||||
}
|
||||
observer.listMonitorDidChange(monitor)
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -367,10 +369,11 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak observer] (monitor) -> Void in
|
||||
|
||||
if let observer = observer {
|
||||
guard let observer = observer else {
|
||||
|
||||
observer.listMonitorWillChange(monitor)
|
||||
return
|
||||
}
|
||||
observer.listMonitorWillChange(monitor)
|
||||
}
|
||||
)
|
||||
self.registerChangeNotification(
|
||||
@@ -379,10 +382,11 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak observer] (monitor) -> Void in
|
||||
|
||||
if let observer = observer {
|
||||
guard let observer = observer else {
|
||||
|
||||
observer.listMonitorDidChange(monitor)
|
||||
return
|
||||
}
|
||||
observer.listMonitorDidChange(monitor)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -392,14 +396,15 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in
|
||||
|
||||
if let observer = observer {
|
||||
guard let observer = observer else {
|
||||
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didInsertObject: object,
|
||||
toIndexPath: newIndexPath!
|
||||
)
|
||||
return
|
||||
}
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didInsertObject: object,
|
||||
toIndexPath: newIndexPath!
|
||||
)
|
||||
}
|
||||
)
|
||||
self.registerObjectNotification(
|
||||
@@ -408,14 +413,15 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in
|
||||
|
||||
if let observer = observer {
|
||||
guard let observer = observer else {
|
||||
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didDeleteObject: object,
|
||||
fromIndexPath: indexPath!
|
||||
)
|
||||
return
|
||||
}
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didDeleteObject: object,
|
||||
fromIndexPath: indexPath!
|
||||
)
|
||||
}
|
||||
)
|
||||
self.registerObjectNotification(
|
||||
@@ -424,14 +430,15 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in
|
||||
|
||||
if let observer = observer {
|
||||
guard let observer = observer else {
|
||||
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didUpdateObject: object,
|
||||
atIndexPath: indexPath!
|
||||
)
|
||||
return
|
||||
}
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didUpdateObject: object,
|
||||
atIndexPath: indexPath!
|
||||
)
|
||||
}
|
||||
)
|
||||
self.registerObjectNotification(
|
||||
@@ -440,15 +447,16 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in
|
||||
|
||||
if let observer = observer {
|
||||
guard let observer = observer else {
|
||||
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didMoveObject: object,
|
||||
fromIndexPath: indexPath!,
|
||||
toIndexPath: newIndexPath!
|
||||
)
|
||||
return
|
||||
}
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didMoveObject: object,
|
||||
fromIndexPath: indexPath!,
|
||||
toIndexPath: newIndexPath!
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -479,10 +487,11 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak observer] (monitor) -> Void in
|
||||
|
||||
if let observer = observer {
|
||||
guard let observer = observer else {
|
||||
|
||||
observer.listMonitorWillChange(monitor)
|
||||
return
|
||||
}
|
||||
observer.listMonitorWillChange(monitor)
|
||||
}
|
||||
)
|
||||
self.registerChangeNotification(
|
||||
@@ -491,10 +500,11 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak observer] (monitor) -> Void in
|
||||
|
||||
if let observer = observer {
|
||||
guard let observer = observer else {
|
||||
|
||||
observer.listMonitorDidChange(monitor)
|
||||
return
|
||||
}
|
||||
observer.listMonitorDidChange(monitor)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -504,14 +514,15 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in
|
||||
|
||||
if let observer = observer {
|
||||
guard let observer = observer else {
|
||||
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didInsertObject: object,
|
||||
toIndexPath: newIndexPath!
|
||||
)
|
||||
return
|
||||
}
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didInsertObject: object,
|
||||
toIndexPath: newIndexPath!
|
||||
)
|
||||
}
|
||||
)
|
||||
self.registerObjectNotification(
|
||||
@@ -520,14 +531,15 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in
|
||||
|
||||
if let observer = observer {
|
||||
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didDeleteObject: object,
|
||||
fromIndexPath: indexPath!
|
||||
)
|
||||
guard let observer = observer else {
|
||||
|
||||
return
|
||||
}
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didDeleteObject: object,
|
||||
fromIndexPath: indexPath!
|
||||
)
|
||||
}
|
||||
)
|
||||
self.registerObjectNotification(
|
||||
@@ -536,14 +548,15 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in
|
||||
|
||||
if let observer = observer {
|
||||
guard let observer = observer else {
|
||||
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didUpdateObject: object,
|
||||
atIndexPath: indexPath!
|
||||
)
|
||||
return
|
||||
}
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didUpdateObject: object,
|
||||
atIndexPath: indexPath!
|
||||
)
|
||||
}
|
||||
)
|
||||
self.registerObjectNotification(
|
||||
@@ -552,15 +565,16 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in
|
||||
|
||||
if let observer = observer {
|
||||
guard let observer = observer else {
|
||||
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didMoveObject: object,
|
||||
fromIndexPath: indexPath!,
|
||||
toIndexPath: newIndexPath!
|
||||
)
|
||||
return
|
||||
}
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didMoveObject: object,
|
||||
fromIndexPath: indexPath!,
|
||||
toIndexPath: newIndexPath!
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -570,14 +584,15 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak observer] (monitor, sectionInfo, sectionIndex) -> Void in
|
||||
|
||||
if let observer = observer {
|
||||
guard let observer = observer else {
|
||||
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didInsertSection: sectionInfo,
|
||||
toSectionIndex: sectionIndex
|
||||
)
|
||||
return
|
||||
}
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didInsertSection: sectionInfo,
|
||||
toSectionIndex: sectionIndex
|
||||
)
|
||||
}
|
||||
)
|
||||
self.registerSectionNotification(
|
||||
@@ -586,14 +601,15 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak observer] (monitor, sectionInfo, sectionIndex) -> Void in
|
||||
|
||||
if let observer = observer {
|
||||
guard let observer = observer else {
|
||||
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didDeleteSection: sectionInfo,
|
||||
fromSectionIndex: sectionIndex
|
||||
)
|
||||
return
|
||||
}
|
||||
observer.listMonitor(
|
||||
monitor,
|
||||
didDeleteSection: sectionInfo,
|
||||
fromSectionIndex: sectionIndex
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -686,10 +702,11 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
object: self,
|
||||
closure: { [weak self] (note) -> Void in
|
||||
|
||||
if let strongSelf = self {
|
||||
guard let strongSelf = self else {
|
||||
|
||||
callback(monitor: strongSelf)
|
||||
return
|
||||
}
|
||||
callback(monitor: strongSelf)
|
||||
}
|
||||
),
|
||||
forKey: notificationKey,
|
||||
@@ -705,17 +722,18 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
object: self,
|
||||
closure: { [weak self] (note) -> Void in
|
||||
|
||||
if let strongSelf = self,
|
||||
guard let strongSelf = self,
|
||||
let userInfo = note.userInfo,
|
||||
let object = userInfo[UserInfoKeyObject] as? T {
|
||||
let object = userInfo[UserInfoKeyObject] as? T else {
|
||||
|
||||
callback(
|
||||
monitor: strongSelf,
|
||||
object: object,
|
||||
indexPath: userInfo[UserInfoKeyIndexPath] as? NSIndexPath,
|
||||
newIndexPath: userInfo[UserInfoKeyNewIndexPath] as? NSIndexPath
|
||||
)
|
||||
return
|
||||
}
|
||||
callback(
|
||||
monitor: strongSelf,
|
||||
object: object,
|
||||
indexPath: userInfo[UserInfoKeyIndexPath] as? NSIndexPath,
|
||||
newIndexPath: userInfo[UserInfoKeyNewIndexPath] as? NSIndexPath
|
||||
)
|
||||
}
|
||||
),
|
||||
forKey: notificationKey,
|
||||
@@ -731,17 +749,18 @@ public final class ListMonitor<T: NSManagedObject> {
|
||||
object: self,
|
||||
closure: { [weak self] (note) -> Void in
|
||||
|
||||
if let strongSelf = self,
|
||||
guard let strongSelf = self,
|
||||
let userInfo = note.userInfo,
|
||||
let sectionInfo = userInfo[UserInfoKeySectionInfo] as? NSFetchedResultsSectionInfo,
|
||||
let sectionIndex = (userInfo[UserInfoKeySectionIndex] as? NSNumber)?.integerValue {
|
||||
let sectionIndex = (userInfo[UserInfoKeySectionIndex] as? NSNumber)?.integerValue else {
|
||||
|
||||
callback(
|
||||
monitor: strongSelf,
|
||||
sectionInfo: sectionInfo,
|
||||
sectionIndex: sectionIndex
|
||||
)
|
||||
return
|
||||
}
|
||||
callback(
|
||||
monitor: strongSelf,
|
||||
sectionInfo: sectionInfo,
|
||||
sectionIndex: sectionIndex
|
||||
)
|
||||
}
|
||||
),
|
||||
forKey: notificationKey,
|
||||
|
||||
@@ -28,20 +28,6 @@ import CoreData
|
||||
import GCDKit
|
||||
|
||||
|
||||
private let ObjectMonitorWillChangeObjectNotification = "ObjectMonitorWillChangeObjectNotification"
|
||||
private let ObjectMonitorDidDeleteObjectNotification = "ObjectMonitorDidDeleteObjectNotification"
|
||||
private let ObjectMonitorDidUpdateObjectNotification = "ObjectMonitorDidUpdateObjectNotification"
|
||||
|
||||
private let UserInfoKeyObject = "UserInfoKeyObject"
|
||||
|
||||
private struct NotificationKey {
|
||||
|
||||
static var willChangeObject: Void?
|
||||
static var didDeleteObject: Void?
|
||||
static var didUpdateObject: Void?
|
||||
}
|
||||
|
||||
|
||||
// MARK: - ObjectMonitor
|
||||
|
||||
/**
|
||||
@@ -100,10 +86,11 @@ public final class ObjectMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak observer] (monitor) -> Void in
|
||||
|
||||
if let object = monitor.object, let observer = observer {
|
||||
guard let object = monitor.object, let observer = observer else {
|
||||
|
||||
observer.objectMonitor(monitor, willUpdateObject: object)
|
||||
return
|
||||
}
|
||||
observer.objectMonitor(monitor, willUpdateObject: object)
|
||||
}
|
||||
)
|
||||
self.registerObjectNotification(
|
||||
@@ -112,10 +99,11 @@ public final class ObjectMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak observer] (monitor, object) -> Void in
|
||||
|
||||
if let observer = observer {
|
||||
guard let observer = observer else {
|
||||
|
||||
observer.objectMonitor(monitor, didDeleteObject: object)
|
||||
return
|
||||
}
|
||||
observer.objectMonitor(monitor, didDeleteObject: object)
|
||||
}
|
||||
)
|
||||
self.registerObjectNotification(
|
||||
@@ -124,27 +112,29 @@ public final class ObjectMonitor<T: NSManagedObject> {
|
||||
toObserver: observer,
|
||||
callback: { [weak self, weak observer] (monitor, object) -> Void in
|
||||
|
||||
if let strongSelf = self, let observer = observer {
|
||||
guard let strongSelf = self, let observer = observer else {
|
||||
|
||||
let previousCommitedAttributes = strongSelf.lastCommittedAttributes
|
||||
let currentCommitedAttributes = object.committedValuesForKeys(nil) as! [String: NSObject]
|
||||
|
||||
var changedKeys = Set<String>()
|
||||
for key in currentCommitedAttributes.keys {
|
||||
|
||||
if previousCommitedAttributes[key] != currentCommitedAttributes[key] {
|
||||
|
||||
changedKeys.insert(key)
|
||||
}
|
||||
}
|
||||
|
||||
strongSelf.lastCommittedAttributes = currentCommitedAttributes
|
||||
observer.objectMonitor(
|
||||
monitor,
|
||||
didUpdateObject: object,
|
||||
changedPersistentKeys: changedKeys
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
let previousCommitedAttributes = strongSelf.lastCommittedAttributes
|
||||
let currentCommitedAttributes = object.committedValuesForKeys(nil) as! [String: NSObject]
|
||||
|
||||
var changedKeys = Set<String>()
|
||||
for key in currentCommitedAttributes.keys {
|
||||
|
||||
if previousCommitedAttributes[key] != currentCommitedAttributes[key] {
|
||||
|
||||
changedKeys.insert(key)
|
||||
}
|
||||
}
|
||||
|
||||
strongSelf.lastCommittedAttributes = currentCommitedAttributes
|
||||
observer.objectMonitor(
|
||||
monitor,
|
||||
didUpdateObject: object,
|
||||
changedPersistentKeys: changedKeys
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -222,10 +212,11 @@ public final class ObjectMonitor<T: NSManagedObject> {
|
||||
object: self,
|
||||
closure: { [weak self] (note) -> Void in
|
||||
|
||||
if let strongSelf = self {
|
||||
guard let strongSelf = self else {
|
||||
|
||||
callback(monitor: strongSelf)
|
||||
return
|
||||
}
|
||||
callback(monitor: strongSelf)
|
||||
}
|
||||
),
|
||||
forKey: notificationKey,
|
||||
@@ -241,15 +232,13 @@ public final class ObjectMonitor<T: NSManagedObject> {
|
||||
object: self,
|
||||
closure: { [weak self] (note) -> Void in
|
||||
|
||||
if let strongSelf = self,
|
||||
guard let strongSelf = self,
|
||||
let userInfo = note.userInfo,
|
||||
let object = userInfo[UserInfoKeyObject] as? T {
|
||||
let object = userInfo[UserInfoKeyObject] as? T else {
|
||||
|
||||
callback(
|
||||
monitor: strongSelf,
|
||||
object: object
|
||||
)
|
||||
return
|
||||
}
|
||||
callback(monitor: strongSelf, object: object)
|
||||
}
|
||||
),
|
||||
forKey: notificationKey,
|
||||
@@ -352,3 +341,17 @@ private final class FetchedResultsControllerDelegate: NSObject, NSFetchedResults
|
||||
self.fetchedResultsController?.delegate = nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private let ObjectMonitorWillChangeObjectNotification = "ObjectMonitorWillChangeObjectNotification"
|
||||
private let ObjectMonitorDidDeleteObjectNotification = "ObjectMonitorDidDeleteObjectNotification"
|
||||
private let ObjectMonitorDidUpdateObjectNotification = "ObjectMonitorDidUpdateObjectNotification"
|
||||
|
||||
private let UserInfoKeyObject = "UserInfoKeyObject"
|
||||
|
||||
private struct NotificationKey {
|
||||
|
||||
static var willChangeObject: Void?
|
||||
static var didDeleteObject: Void?
|
||||
static var didUpdateObject: Void?
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user