remove warnings when calling unsafeBitCast()

This commit is contained in:
John Estropia
2017-03-09 18:59:37 +09:00
parent f21e4e12e0
commit fe25a9aa36
4 changed files with 58 additions and 3 deletions

View File

@@ -35,6 +35,21 @@ import CoreStore
class ListObserverTests: BaseTestDataTestCase {
@objc
dynamic func test_ThatListObservers_CanDowncast() {
self.prepareStack { (stack) in
let monitor = stack.monitorSectionedList(
From<TestEntity1>(),
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() {

View File

@@ -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<TestEntity1>(),
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() {

View File

@@ -677,7 +677,12 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
internal func downcast() -> ListMonitor<NSManagedObject> {
return unsafeBitCast(self, to: ListMonitor<NSManagedObject>.self)
@inline(__always)
func noWarnUnsafeBitCast<T, U>(_ x: T, to type: U.Type) -> U {
return unsafeBitCast(x, to: type)
}
return noWarnUnsafeBitCast(self, to: ListMonitor<NSManagedObject>.self)
}
internal func registerChangeNotification(_ notificationKey: UnsafeRawPointer, name: Notification.Name, toObserver observer: AnyObject, callback: @escaping (_ monitor: ListMonitor<T>) -> Void) {

View File

@@ -110,11 +110,21 @@ public final class ObjectMonitor<EntityType: NSManagedObject>: Equatable {
return lhs === rhs
}
public static func == <T: NSManagedObject, U: NSManagedObject>(lhs: ObjectMonitor<T>, rhs: ObjectMonitor<U>) -> Bool {
return lhs.fetchedResultsController === rhs.fetchedResultsController
}
public static func ~= <T: NSManagedObject>(lhs: ObjectMonitor<T>, rhs: ObjectMonitor<T>) -> Bool {
return lhs === rhs
}
public static func ~= <T: NSManagedObject, U: NSManagedObject>(lhs: ObjectMonitor<T>, rhs: ObjectMonitor<U>) -> Bool {
return lhs.fetchedResultsController === rhs.fetchedResultsController
}
// MARK: Hashable
@@ -212,7 +222,12 @@ public final class ObjectMonitor<EntityType: NSManagedObject>: Equatable {
internal func downcast() -> ObjectMonitor<NSManagedObject> {
return unsafeBitCast(self, to: ObjectMonitor<NSManagedObject>.self)
@inline(__always)
func noWarnUnsafeBitCast<T, U>(_ x: T, to type: U.Type) -> U {
return unsafeBitCast(x, to: type)
}
return noWarnUnsafeBitCast(self, to: ObjectMonitor<NSManagedObject>.self)
}
deinit {