mirror of
https://github.com/HackPlan/realm-cocoa.git
synced 2026-04-30 11:01:48 +08:00
Bridge Optional to NSNull (#4057)
This commit is contained in:
@@ -531,8 +531,11 @@ class RealmTests: TestCase {
|
||||
realm.createObject(ofType: type, populatedWith: ["b", 2])
|
||||
}
|
||||
|
||||
let object1 = realm.object(ofType: type, forPrimaryKey: NSNull())
|
||||
XCTAssertNotNil(object1)
|
||||
let object1a = realm.object(ofType: type, forPrimaryKey: NSNull())
|
||||
XCTAssertNotNil(object1a)
|
||||
|
||||
let object1b = realm.object(ofType: type, forPrimaryKey: nil as Wrapped?)
|
||||
XCTAssertNotNil(object1b)
|
||||
|
||||
let object2 = realm.object(ofType: type, forPrimaryKey: 2 as Wrapped)
|
||||
XCTAssertNotNil(object2)
|
||||
@@ -1270,8 +1273,11 @@ class RealmTests: TestCase {
|
||||
realm.create(type, value: ["b", 2])
|
||||
}
|
||||
|
||||
let object1 = realm.objectForPrimaryKey(type, key: NSNull())
|
||||
XCTAssertNotNil(object1)
|
||||
let object1a = realm.objectForPrimaryKey(type, key: NSNull())
|
||||
XCTAssertNotNil(object1a)
|
||||
|
||||
let object1b = realm.objectForPrimaryKey(type, key: nil as Int?)
|
||||
XCTAssertNotNil(object1b)
|
||||
|
||||
let object2 = realm.objectForPrimaryKey(type, key: 2)
|
||||
XCTAssertNotNil(object2)
|
||||
|
||||
@@ -113,6 +113,22 @@ extension Int64: CustomObjectiveCBridgeable {
|
||||
return NSNumber(value: self)
|
||||
}
|
||||
}
|
||||
extension Optional: CustomObjectiveCBridgeable {
|
||||
static func bridging(objCValue: Any) -> Optional {
|
||||
if objCValue is NSNull {
|
||||
return nil
|
||||
} else {
|
||||
return .some(dynamicBridgeCast(fromObjectiveC: objCValue))
|
||||
}
|
||||
}
|
||||
var objCValue: Any {
|
||||
if let value = self {
|
||||
return value
|
||||
} else {
|
||||
return NSNull()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
|
||||
Reference in New Issue
Block a user