diff --git a/CoreStoreTests/ListObserverTests.swift b/CoreStoreTests/ListObserverTests.swift index 987d4de..f84cd4c 100644 --- a/CoreStoreTests/ListObserverTests.swift +++ b/CoreStoreTests/ListObserverTests.swift @@ -35,6 +35,21 @@ import CoreStore class ListObserverTests: BaseTestDataTestCase { + @objc + dynamic func test_ThatListObservers_CanDowncast() { + + self.prepareStack { (stack) in + + let monitor = stack.monitorSectionedList( + From(), + SectionBy(#keyPath(TestEntity1.testBoolean)), + OrderBy(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID))) + ) + let downcast = monitor.downcast() + XCTAssertTrue(monitor == downcast) + } + } + @objc dynamic func test_ThatListObservers_CanReceiveInsertNotifications() { diff --git a/CoreStoreTests/ObjectObserverTests.swift b/CoreStoreTests/ObjectObserverTests.swift index 7884462..e2fa9f8 100644 --- a/CoreStoreTests/ObjectObserverTests.swift +++ b/CoreStoreTests/ObjectObserverTests.swift @@ -33,7 +33,27 @@ import CoreStore // MARK: - ObjectObserverTests -class ObjectObserverTests: BaseTestDataTestCase { + class ObjectObserverTests: BaseTestDataTestCase { + + @objc + dynamic func test_ThatObjectObservers_CanDowncast() { + + self.prepareStack { (stack) in + + self.prepareTestDataForStack(stack) + + guard let object = stack.fetchOne( + From(), + Where(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) else { + + XCTFail() + return + } + let monitor = stack.monitorObject(object) + let downcast = monitor.downcast() + XCTAssertTrue(monitor == downcast) + } + } @objc dynamic func test_ThatObjectObservers_CanReceiveUpdateNotifications() { diff --git a/Sources/Observing/ListMonitor.swift b/Sources/Observing/ListMonitor.swift index ad96481..dca47f5 100644 --- a/Sources/Observing/ListMonitor.swift +++ b/Sources/Observing/ListMonitor.swift @@ -677,7 +677,12 @@ public final class ListMonitor: Hashable { internal func downcast() -> ListMonitor { - return unsafeBitCast(self, to: ListMonitor.self) + @inline(__always) + func noWarnUnsafeBitCast(_ x: T, to type: U.Type) -> U { + + return unsafeBitCast(x, to: type) + } + return noWarnUnsafeBitCast(self, to: ListMonitor.self) } internal func registerChangeNotification(_ notificationKey: UnsafeRawPointer, name: Notification.Name, toObserver observer: AnyObject, callback: @escaping (_ monitor: ListMonitor) -> Void) { diff --git a/Sources/Observing/ObjectMonitor.swift b/Sources/Observing/ObjectMonitor.swift index 9956a75..88adf35 100644 --- a/Sources/Observing/ObjectMonitor.swift +++ b/Sources/Observing/ObjectMonitor.swift @@ -110,11 +110,21 @@ public final class ObjectMonitor: Equatable { return lhs === rhs } + public static func == (lhs: ObjectMonitor, rhs: ObjectMonitor) -> Bool { + + return lhs.fetchedResultsController === rhs.fetchedResultsController + } + public static func ~= (lhs: ObjectMonitor, rhs: ObjectMonitor) -> Bool { return lhs === rhs } + public static func ~= (lhs: ObjectMonitor, rhs: ObjectMonitor) -> Bool { + + return lhs.fetchedResultsController === rhs.fetchedResultsController + } + // MARK: Hashable @@ -212,7 +222,12 @@ public final class ObjectMonitor: Equatable { internal func downcast() -> ObjectMonitor { - return unsafeBitCast(self, to: ObjectMonitor.self) + @inline(__always) + func noWarnUnsafeBitCast(_ x: T, to type: U.Type) -> U { + + return unsafeBitCast(x, to: type) + } + return noWarnUnsafeBitCast(self, to: ObjectMonitor.self) } deinit {