mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-29 13:51:48 +02:00
Add debugDescription implementation for new Publisher and Snapshot types
This commit is contained in:
@@ -373,15 +373,34 @@ fileprivate struct CoreStoreFetchedSectionInfoWrapper: CoreStoreDebugStringConve
|
|||||||
var coreStoreDumpString: String {
|
var coreStoreDumpString: String {
|
||||||
|
|
||||||
return createFormattedString(
|
return createFormattedString(
|
||||||
"\"\(self.sectionInfo.name)\" (", ")",
|
"\"\(self.sectionName)\" (", ")",
|
||||||
("numberOfObjects", self.sectionInfo.numberOfObjects),
|
("numberOfObjects", self.numberOfObjects),
|
||||||
("indexTitle", self.sectionInfo.indexTitle as Any)
|
("indexTitle", self.sectionIndexTitle as Any)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: FilePrivate
|
// MARK: FilePrivate
|
||||||
|
|
||||||
let sectionInfo: NSFetchedResultsSectionInfo
|
fileprivate init(_ sectionInfo: NSFetchedResultsSectionInfo) {
|
||||||
|
|
||||||
|
self.sectionName = sectionInfo.name
|
||||||
|
self.numberOfObjects = sectionInfo.numberOfObjects
|
||||||
|
self.sectionIndexTitle = sectionInfo.indexTitle
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate init(_ section: Internals.DiffableDataSourceSnapshot.Section) {
|
||||||
|
|
||||||
|
self.sectionName = section.differenceIdentifier
|
||||||
|
self.numberOfObjects = section.elements.count
|
||||||
|
self.sectionIndexTitle = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: Private
|
||||||
|
|
||||||
|
private let sectionName: String
|
||||||
|
private let sectionIndexTitle: String?
|
||||||
|
private let numberOfObjects: Int
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(macOS 10.12, *)
|
@available(macOS 10.12, *)
|
||||||
@@ -409,6 +428,56 @@ extension ListMonitor: CustomDebugStringConvertible, CoreStoreDebugStringConvert
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: - ListPublisher
|
||||||
|
|
||||||
|
@available(macOS 10.12, *)
|
||||||
|
extension ListPublisher: CustomDebugStringConvertible, CoreStoreDebugStringConvertible {
|
||||||
|
|
||||||
|
// MARK: CustomDebugStringConvertible
|
||||||
|
|
||||||
|
public var debugDescription: String {
|
||||||
|
|
||||||
|
return formattedDebugDescription(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: CoreStoreDebugStringConvertible
|
||||||
|
|
||||||
|
public var coreStoreDumpString: String {
|
||||||
|
|
||||||
|
return createFormattedString(
|
||||||
|
"(", ")",
|
||||||
|
("snapshot", self.snapshot)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: - ListSnapshot
|
||||||
|
|
||||||
|
extension ListSnapshot: CustomDebugStringConvertible, CoreStoreDebugStringConvertible {
|
||||||
|
|
||||||
|
// MARK: CustomDebugStringConvertible
|
||||||
|
|
||||||
|
public var debugDescription: String {
|
||||||
|
|
||||||
|
return formattedDebugDescription(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: CoreStoreDebugStringConvertible
|
||||||
|
|
||||||
|
public var coreStoreDumpString: String {
|
||||||
|
|
||||||
|
return createFormattedString(
|
||||||
|
"(", ")",
|
||||||
|
("numberOfObjects", self.numberOfItems),
|
||||||
|
("sections", self.diffableSnapshot.sections.map(CoreStoreFetchedSectionInfoWrapper.init))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: - LocalStorageOptions
|
// MARK: - LocalStorageOptions
|
||||||
|
|
||||||
extension LocalStorageOptions: CustomDebugStringConvertible, CoreStoreDebugStringConvertible {
|
extension LocalStorageOptions: CustomDebugStringConvertible, CoreStoreDebugStringConvertible {
|
||||||
@@ -568,6 +637,56 @@ extension ObjectMonitor: CustomDebugStringConvertible, CoreStoreDebugStringConve
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: - ObjectPublisher
|
||||||
|
|
||||||
|
extension ObjectPublisher: CustomDebugStringConvertible, CoreStoreDebugStringConvertible {
|
||||||
|
|
||||||
|
// MARK: CustomDebugStringConvertible
|
||||||
|
|
||||||
|
public var debugDescription: String {
|
||||||
|
|
||||||
|
return formattedDebugDescription(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: CoreStoreDebugStringConvertible
|
||||||
|
|
||||||
|
public var coreStoreDumpString: String {
|
||||||
|
|
||||||
|
return createFormattedString(
|
||||||
|
"(", ")",
|
||||||
|
("objectID", self.objectID()),
|
||||||
|
("object", self.object as Any)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: - ObjectSnapshot
|
||||||
|
|
||||||
|
extension ObjectSnapshot: CustomDebugStringConvertible, CoreStoreDebugStringConvertible {
|
||||||
|
|
||||||
|
// MARK: CustomDebugStringConvertible
|
||||||
|
|
||||||
|
public var debugDescription: String {
|
||||||
|
|
||||||
|
return formattedDebugDescription(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: CoreStoreDebugStringConvertible
|
||||||
|
|
||||||
|
public var coreStoreDumpString: String {
|
||||||
|
|
||||||
|
return createFormattedString(
|
||||||
|
"(", ")",
|
||||||
|
("objectID", self.objectID()),
|
||||||
|
("dictionaryForValues", self.dictionaryForValues())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: - OrderBy
|
// MARK: - OrderBy
|
||||||
|
|
||||||
extension OrderBy: CustomDebugStringConvertible, CoreStoreDebugStringConvertible {
|
extension OrderBy: CustomDebugStringConvertible, CoreStoreDebugStringConvertible {
|
||||||
|
|||||||
@@ -127,31 +127,19 @@ extension DiffableDataSource {
|
|||||||
@nonobjc
|
@nonobjc
|
||||||
public func apply(_ snapshot: ListSnapshot<O>, animatingDifferences: Bool = true) {
|
public func apply(_ snapshot: ListSnapshot<O>, animatingDifferences: Bool = true) {
|
||||||
|
|
||||||
let diffableSnapshot = snapshot.diffableSnapshot
|
self.dispatcher.apply(
|
||||||
// if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) {
|
snapshot.diffableSnapshot,
|
||||||
//
|
view: self.tableView,
|
||||||
// self.modernDataSource.apply(
|
animatingDifferences: animatingDifferences,
|
||||||
// diffableSnapshot as! NSDiffableDataSourceSnapshot<String, NSManagedObjectID>,
|
performUpdates: { tableView, changeset, setSections in
|
||||||
// animatingDifferences: animatingDifferences,
|
|
||||||
// completion: nil
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
|
|
||||||
self.dispatcher.apply(
|
tableView.reload(
|
||||||
diffableSnapshot as! Internals.DiffableDataSourceSnapshot,
|
using: changeset,
|
||||||
view: self.tableView,
|
with: self.defaultRowAnimation,
|
||||||
animatingDifferences: animatingDifferences,
|
setData: setSections
|
||||||
performUpdates: { tableView, changeset, setSections in
|
)
|
||||||
|
}
|
||||||
tableView.reload(
|
)
|
||||||
using: changeset,
|
|
||||||
with: self.defaultRowAnimation,
|
|
||||||
setData: setSections
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -41,9 +41,6 @@ import AppKit
|
|||||||
|
|
||||||
internal protocol FetchedDiffableDataSourceSnapshotHandler: AnyObject {
|
internal protocol FetchedDiffableDataSourceSnapshotHandler: AnyObject {
|
||||||
|
|
||||||
// @available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
|
|
||||||
// func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChangeContentWith snapshot: NSDiffableDataSourceSnapshot<String, NSManagedObjectID>)
|
|
||||||
|
|
||||||
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChangeContentWith snapshot: Internals.DiffableDataSourceSnapshot)
|
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChangeContentWith snapshot: Internals.DiffableDataSourceSnapshot)
|
||||||
|
|
||||||
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, sectionIndexTitleForSectionName sectionName: String?) -> String?
|
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, sectionIndexTitleForSectionName sectionName: String?) -> String?
|
||||||
@@ -80,15 +77,6 @@ extension Internals {
|
|||||||
|
|
||||||
internal func initialFetch() {
|
internal func initialFetch() {
|
||||||
|
|
||||||
// #if canImport(UIKit) || canImport(AppKit)
|
|
||||||
//
|
|
||||||
// if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) {
|
|
||||||
//
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
guard let fetchedResultsController = self.fetchedResultsController else {
|
guard let fetchedResultsController = self.fetchedResultsController else {
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -99,20 +87,6 @@ extension Internals {
|
|||||||
|
|
||||||
// MARK: NSFetchedResultsControllerDelegate
|
// MARK: NSFetchedResultsControllerDelegate
|
||||||
|
|
||||||
// #if canImport(UIKit) || canImport(AppKit)
|
|
||||||
//
|
|
||||||
// @available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
|
|
||||||
// @objc
|
|
||||||
// dynamic func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChangeContentWith snapshot: NSDiffableDataSourceSnapshotReference) {
|
|
||||||
//
|
|
||||||
// self.handler?.controller(
|
|
||||||
// controller,
|
|
||||||
// didChangeContentWith: snapshot as NSDiffableDataSourceSnapshot<String, NSManagedObjectID>
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
dynamic func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
|
dynamic func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
|
||||||
|
|
||||||
|
|||||||
@@ -398,15 +398,6 @@ extension ListPublisher: FetchedDiffableDataSourceSnapshotHandler {
|
|||||||
|
|
||||||
// MARK: FetchedDiffableDataSourceSnapshotHandler
|
// MARK: FetchedDiffableDataSourceSnapshotHandler
|
||||||
|
|
||||||
// @available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
|
|
||||||
// internal func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChangeContentWith snapshot: NSDiffableDataSourceSnapshot<String, NSManagedObjectID>) {
|
|
||||||
//
|
|
||||||
// self.snapshot = .init(
|
|
||||||
// diffableSnapshot: snapshot,
|
|
||||||
// context: controller.managedObjectContext
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
|
|
||||||
internal func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChangeContentWith snapshot: Internals.DiffableDataSourceSnapshot) {
|
internal func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChangeContentWith snapshot: Internals.DiffableDataSourceSnapshot) {
|
||||||
|
|
||||||
self.snapshot = .init(
|
self.snapshot = .init(
|
||||||
|
|||||||
@@ -629,28 +629,14 @@ public struct ListSnapshot<O: DynamicObject>: RandomAccessCollection, Hashable {
|
|||||||
|
|
||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|
||||||
internal private(set) var diffableSnapshot: DiffableDataSourceSnapshotProtocol
|
internal private(set) var diffableSnapshot: Internals.DiffableDataSourceSnapshot
|
||||||
|
|
||||||
internal init() {
|
internal init() {
|
||||||
|
|
||||||
// if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) {
|
self.diffableSnapshot = Internals.DiffableDataSourceSnapshot()
|
||||||
//
|
|
||||||
// self.diffableSnapshot = NSDiffableDataSourceSnapshot<String, NSManagedObjectID>()
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
|
|
||||||
self.diffableSnapshot = Internals.DiffableDataSourceSnapshot()
|
|
||||||
// }
|
|
||||||
self.context = nil
|
self.context = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
|
|
||||||
// internal init(diffableSnapshot: NSDiffableDataSourceSnapshot<String, NSManagedObjectID>, context: NSManagedObjectContext) {
|
|
||||||
//
|
|
||||||
// self.diffableSnapshot = diffableSnapshot
|
|
||||||
// self.context = context
|
|
||||||
// }
|
|
||||||
|
|
||||||
internal init(diffableSnapshot: Internals.DiffableDataSourceSnapshot, context: NSManagedObjectContext) {
|
internal init(diffableSnapshot: Internals.DiffableDataSourceSnapshot, context: NSManagedObjectContext) {
|
||||||
|
|
||||||
self.diffableSnapshot = diffableSnapshot
|
self.diffableSnapshot = diffableSnapshot
|
||||||
|
|||||||
@@ -336,7 +336,6 @@ extension ObjectPublisher {
|
|||||||
|
|
||||||
// MARK: - ObjectPublisher where O: NSManagedObject
|
// MARK: - ObjectPublisher where O: NSManagedObject
|
||||||
|
|
||||||
@available(*, unavailable, message: "KeyPaths accessed from @dynamicMemberLookup types can't generate KVC keys yet (https://bugs.swift.org/browse/SR-11351)")
|
|
||||||
extension ObjectPublisher where O: NSManagedObject {
|
extension ObjectPublisher where O: NSManagedObject {
|
||||||
|
|
||||||
// MARK: Public
|
// MARK: Public
|
||||||
@@ -344,11 +343,21 @@ extension ObjectPublisher where O: NSManagedObject {
|
|||||||
/**
|
/**
|
||||||
Returns the value for the property identified by a given key.
|
Returns the value for the property identified by a given key.
|
||||||
*/
|
*/
|
||||||
|
@available(*, unavailable, message: "KeyPaths accessed from @dynamicMemberLookup types can't generate KVC keys yet (https://bugs.swift.org/browse/SR-11351)")
|
||||||
public subscript<V: AllowedObjectiveCKeyPathValue>(dynamicMember member: KeyPath<O, V>) -> V {
|
public subscript<V: AllowedObjectiveCKeyPathValue>(dynamicMember member: KeyPath<O, V>) -> V {
|
||||||
|
|
||||||
fatalError()
|
fatalError()
|
||||||
// return self.snapshot[dynamicMember: member]
|
// return self.snapshot[dynamicMember: member]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the value for the property identified by a given key.
|
||||||
|
*/
|
||||||
|
public func value<V: AllowedObjectiveCKeyPathValue>(forKeyPath keyPath: KeyPath<O, V>) -> V! {
|
||||||
|
|
||||||
|
let key = String(keyPath: keyPath)
|
||||||
|
return self.snapshot?.dictionaryForValues()[key] as! V?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,14 @@ import AppKit
|
|||||||
@dynamicMemberLookup
|
@dynamicMemberLookup
|
||||||
public struct ObjectSnapshot<O: DynamicObject>: ObjectRepresentation, Hashable {
|
public struct ObjectSnapshot<O: DynamicObject>: ObjectRepresentation, Hashable {
|
||||||
|
|
||||||
|
// MARK: Public
|
||||||
|
|
||||||
|
public func dictionaryForValues() -> [String: Any] {
|
||||||
|
|
||||||
|
return self.values
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: ObjectRepresentation
|
// MARK: ObjectRepresentation
|
||||||
|
|
||||||
public typealias ObjectType = O
|
public typealias ObjectType = O
|
||||||
@@ -127,17 +135,26 @@ public struct ObjectSnapshot<O: DynamicObject>: ObjectRepresentation, Hashable {
|
|||||||
|
|
||||||
// MARK: - ObjectSnapshot where O: NSManagedObject
|
// MARK: - ObjectSnapshot where O: NSManagedObject
|
||||||
|
|
||||||
@available(*, unavailable, message: "KeyPaths accessed from @dynamicMemberLookup types can't generate KVC keys yet (https://bugs.swift.org/browse/SR-11351)")
|
|
||||||
extension ObjectSnapshot where O: NSManagedObject {
|
extension ObjectSnapshot where O: NSManagedObject {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the value for the property identified by a given key.
|
Returns the value for the property identified by a given key.
|
||||||
*/
|
*/
|
||||||
|
@available(*, unavailable, message: "KeyPaths accessed from @dynamicMemberLookup types can't generate KVC keys yet (https://bugs.swift.org/browse/SR-11351)")
|
||||||
public subscript<V: AllowedObjectiveCKeyPathValue>(dynamicMember member: KeyPath<O, V>) -> V {
|
public subscript<V: AllowedObjectiveCKeyPathValue>(dynamicMember member: KeyPath<O, V>) -> V {
|
||||||
|
|
||||||
let key = String(keyPath: member)
|
let key = String(keyPath: member)
|
||||||
return self.values[key] as! V
|
return self.values[key] as! V
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the value for the property identified by a given key.
|
||||||
|
*/
|
||||||
|
public func value<V: AllowedObjectiveCKeyPathValue>(forKeyPath keyPath: KeyPath<O, V>) -> V! {
|
||||||
|
|
||||||
|
let key = String(keyPath: keyPath)
|
||||||
|
return self.values[key] as! V?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user