Eliminate most remaining uses of _convertNSFooToFoo and _convertFooToNSFoo.

Generalized bridging has fully subsumed most of these. NSError is
still special, and _convertStringToNSString remains for the the
runtime's implementation of SwiftObject's -description method.
This commit is contained in:
Doug Gregor
2016-03-18 10:31:30 -07:00
parent 4c49e67780
commit d92ae77076
11 changed files with 103 additions and 213 deletions

View File

@@ -146,17 +146,9 @@ GET_BRIDGING_FN(ObjectiveC, REQUIRED, Bool, REQUIRED, ObjCBool)
GET_BRIDGING_FN(ObjectiveC, REQUIRED, ObjCBool, REQUIRED, Bool) GET_BRIDGING_FN(ObjectiveC, REQUIRED, ObjCBool, REQUIRED, Bool)
GET_BRIDGING_FN(Foundation, OPTIONAL, NSError, REQUIRED, ErrorProtocol) GET_BRIDGING_FN(Foundation, OPTIONAL, NSError, REQUIRED, ErrorProtocol)
GET_BRIDGING_FN(Foundation, REQUIRED, ErrorProtocol, REQUIRED, NSError) GET_BRIDGING_FN(Foundation, REQUIRED, ErrorProtocol, REQUIRED, NSError)
GET_BRIDGING_FN(Foundation, REQUIRED, String, REQUIRED, NSString)
GET_BRIDGING_FN(Foundation, OPTIONAL, NSString, REQUIRED, String)
GET_BRIDGING_FN(Foundation, GENERIC, Array, REQUIRED, NSArray)
GET_BRIDGING_FN(Foundation, OPTIONAL, NSArray, GENERIC, Array)
GET_BRIDGING_FN(Foundation, GENERIC, Set, REQUIRED, NSSet)
GET_BRIDGING_FN(Foundation, OPTIONAL, NSSet, GENERIC, Set)
GET_BRIDGING_FN(Foundation, GENERIC, Dictionary, REQUIRED, NSDictionary)
GET_BRIDGING_FN(Foundation, OPTIONAL, NSDictionary, GENERIC, Dictionary)
#undef GET_BRIDGING_FN #undef GET_BRIDGING_FN
#undef REQURIED #undef REQUIRED
#undef OPTIONAL #undef OPTIONAL
#undef GENERIC #undef GENERIC

View File

@@ -2172,21 +2172,6 @@ static void checkBridgedFunctions(TypeChecker &TC) {
#include "swift/SIL/BridgedTypes.def" #include "swift/SIL/BridgedTypes.def"
if (Module *module = TC.Context.getLoadedModule(TC.Context.Id_Foundation)) { if (Module *module = TC.Context.getLoadedModule(TC.Context.Id_Foundation)) {
checkObjCBridgingFunctions(TC, module,
TC.Context.getSwiftName(
KnownFoundationEntity::NSArray),
"_convertNSArrayToArray",
"_convertArrayToNSArray");
checkObjCBridgingFunctions(TC, module,
TC.Context.getSwiftName(
KnownFoundationEntity::NSDictionary),
"_convertNSDictionaryToDictionary",
"_convertDictionaryToNSDictionary");
checkObjCBridgingFunctions(TC, module,
TC.Context.getSwiftName(
KnownFoundationEntity::NSSet),
"_convertNSSetToSet",
"_convertSetToNSSet");
checkObjCBridgingFunctions(TC, module, checkObjCBridgingFunctions(TC, module,
TC.Context.getSwiftName( TC.Context.getSwiftName(
KnownFoundationEntity::NSError), KnownFoundationEntity::NSError),

View File

@@ -75,16 +75,6 @@ func _convertStringToNSString(string: String) -> NSString {
return string._bridgeToObjectiveC() return string._bridgeToObjectiveC()
} }
@warn_unused_result
@_semantics("convertFromObjectiveC")
public // COMPILER_INTRINSIC
func _convertNSStringToString(nsstring: NSString?) -> String {
if nsstring == nil { return "" }
var result: String?
String._forceBridgeFromObjectiveC(nsstring!, result: &result)
return result!
}
extension NSString : StringLiteralConvertible { extension NSString : StringLiteralConvertible {
/// Create an instance initialized to `value`. /// Create an instance initialized to `value`.
public required convenience init(unicodeScalarLiteral value: StaticString) { public required convenience init(unicodeScalarLiteral value: StaticString) {
@@ -461,33 +451,6 @@ extension NSArray : ArrayLiteralConvertible {
} }
} }
/// The entry point for converting `NSArray` to `Array` in bridge
/// thunks. Used, for example, to expose :
///
/// func f([NSView]) {}
///
/// to Objective-C code as a method that accepts an `NSArray`. This operation
/// is referred to as a "forced conversion" in ../../../docs/Arrays.rst
@warn_unused_result
@_semantics("convertFromObjectiveC")
public func _convertNSArrayToArray<T>(source: NSArray?) -> [T] {
if _slowPath(source == nil) { return [] }
var result: [T]?
Array._forceBridgeFromObjectiveC(source!, result: &result)
return result!
}
/// The entry point for converting `Array` to `NSArray` in bridge
/// thunks. Used, for example, to expose :
///
/// func f() -> [NSView] { return [] }
///
/// to Objective-C code as a method that returns an `NSArray`.
@warn_unused_result
public func _convertArrayToNSArray<T>(array: [T]) -> NSArray {
return array._bridgeToObjectiveC()
}
extension Array : _ObjectiveCBridgeable { extension Array : _ObjectiveCBridgeable {
/// Private initializer used for bridging. /// Private initializer used for bridging.
@@ -626,54 +589,6 @@ extension Dictionary {
} }
} }
/// The entry point for bridging `NSDictionary` to `Dictionary` in bridge
/// thunks. Used, for example, to expose:
///
/// func f([String : String]) {}
///
/// to Objective-C code as a method that accepts an `NSDictionary`.
///
/// This is a forced downcast. This operation should have O(1) complexity
/// when `Key` and `Value` are bridged verbatim.
///
/// The cast can fail if bridging fails. The actual checks and bridging can be
/// deferred.
@warn_unused_result
@_semantics("convertFromObjectiveC")
public func _convertNSDictionaryToDictionary<
Key : Hashable, Value
>(d: NSDictionary?) -> [Key : Value] {
// Note: there should be *a good justification* for doing something else
// than just dispatching to `_forceBridgeFromObjectiveC`.
if _slowPath(d == nil) { return [:] }
var result: [Key : Value]?
Dictionary._forceBridgeFromObjectiveC(d!, result: &result)
return result!
}
// FIXME: right now the following is O(n), not O(1).
/// The entry point for bridging `Dictionary` to `NSDictionary` in bridge
/// thunks. Used, for example, to expose:
///
/// func f() -> [String : String] {}
///
/// to Objective-C code as a method that returns an `NSDictionary`.
///
/// This is a forced downcast. This operation should have O(1) complexity.
///
/// The cast can fail if bridging fails. The actual checks and bridging can be
/// deferred.
@warn_unused_result
public func _convertDictionaryToNSDictionary<Key, Value>(
d: [Key : Value]
) -> NSDictionary {
// Note: there should be *a good justification* for doing something else
// than just dispatching to `_bridgeToObjectiveC`.
return d._bridgeToObjectiveC()
}
// Dictionary<Key, Value> is conditionally bridged to NSDictionary // Dictionary<Key, Value> is conditionally bridged to NSDictionary
extension Dictionary : _ObjectiveCBridgeable { extension Dictionary : _ObjectiveCBridgeable {
public static func _getObjectiveCType() -> Any.Type { public static func _getObjectiveCType() -> Any.Type {
@@ -925,45 +840,6 @@ extension NSIndexSet : Sequence {
} }
} }
// FIXME: right now the following is O(n), not O(1).
/// The entry point for bridging `Set` to `NSSet` in bridge
/// thunks. Used, for example, to expose:
///
/// func f() -> Set<String> {}
///
/// to Objective-C code as a method that returns an `NSSet`.
///
/// This is a forced downcast. This operation should have O(1) complexity.
///
/// The cast can fail if bridging fails. The actual checks and bridging can be
/// deferred.
@warn_unused_result
public func _convertSetToNSSet<T>(s: Set<T>) -> NSSet {
return s._bridgeToObjectiveC()
}
/// The entry point for bridging `NSSet` to `Set` in bridge
/// thunks. Used, for example, to expose:
///
/// func f(Set<String>) {}
///
/// to Objective-C code as a method that accepts an `NSSet`.
///
/// This is a forced downcast. This operation should have O(1) complexity
/// when `T` is bridged verbatim.
///
/// The cast can fail if bridging fails. The actual checks and bridging can be
/// deferred.
@warn_unused_result
@_semantics("convertFromObjectiveC")
public func _convertNSSetToSet<T : Hashable>(s: NSSet?) -> Set<T> {
if _slowPath(s == nil) { return [] }
var result: Set<T>?
Set._forceBridgeFromObjectiveC(s!, result: &result)
return result!
}
// Set<Element> is conditionally bridged to NSSet // Set<Element> is conditionally bridged to NSSet
extension Set : _ObjectiveCBridgeable { extension Set : _ObjectiveCBridgeable {
public static func _getObjectiveCType() -> Any.Type { public static func _getObjectiveCType() -> Any.Type {

View File

@@ -384,7 +384,7 @@ extension String {
if let matches = nsMatches { if let matches = nsMatches {
// Since this function is effectively a bridge thunk, use the // Since this function is effectively a bridge thunk, use the
// bridge thunk semantics for the NSArray conversion // bridge thunk semantics for the NSArray conversion
matchesIntoArray._setIfNonNil { _convertNSArrayToArray(matches) } matchesIntoArray._setIfNonNil { return matches as! [String] }
} }
if let n = nsOutputName { if let n = nsOutputName {
@@ -406,7 +406,7 @@ extension String {
let nsa = _ns.componentsSeparatedByCharacters(in: separator) as NSArray let nsa = _ns.componentsSeparatedByCharacters(in: separator) as NSArray
// Since this function is effectively a bridge thunk, use the // Since this function is effectively a bridge thunk, use the
// bridge thunk semantics for the NSArray conversion // bridge thunk semantics for the NSArray conversion
return _convertNSArrayToArray(nsa) return nsa as! [String]
} }
@@ -418,7 +418,7 @@ extension String {
let nsa = _ns.componentsSeparated(by: separator) as NSArray let nsa = _ns.componentsSeparated(by: separator) as NSArray
// Since this function is effectively a bridge thunk, use the // Since this function is effectively a bridge thunk, use the
// bridge thunk semantics for the NSArray conversion // bridge thunk semantics for the NSArray conversion
return _convertNSArrayToArray(nsa) return nsa as! [String]
} }
// - (const char *)cStringUsingEncoding:(NSStringEncoding)encoding // - (const char *)cStringUsingEncoding:(NSStringEncoding)encoding
@@ -1040,7 +1040,7 @@ extension String {
} }
} }
return _convertNSArrayToArray(result) return result as! [String]
} }
// - (NSComparisonResult)localizedCaseInsensitiveCompare:(NSString *)aString // - (NSComparisonResult)localizedCaseInsensitiveCompare:(NSString *)aString

View File

@@ -115,7 +115,7 @@ class ViolateInoutSafetySwitchToObjcBuffer {
@inline(never) @inline(never)
func accessArrayViaInoutViolation() { func accessArrayViaInoutViolation() {
anArray = _convertNSArrayToArray(nsArray) anArray = nsArray as! [ElementClass]
} }
@inline(never) @inline(never)

View File

@@ -3,6 +3,21 @@ import Darwin
import StdlibUnittest import StdlibUnittest
import Foundation import Foundation
func convertDictionaryToNSDictionary<Key, Value>(
d: [Key : Value]
) -> NSDictionary {
return d._bridgeToObjectiveC()
}
public func convertNSDictionaryToDictionary<
Key : Hashable, Value
>(d: NSDictionary?) -> [Key : Value] {
if _slowPath(d == nil) { return [:] }
var result: [Key : Value]?
Dictionary._forceBridgeFromObjectiveC(d!, result: &result)
return result!
}
func isNativeDictionary<KeyTy : Hashable, ValueTy>( func isNativeDictionary<KeyTy : Hashable, ValueTy>(
d: Dictionary<KeyTy, ValueTy>) -> Bool { d: Dictionary<KeyTy, ValueTy>) -> Bool {
switch d._variantStorage { switch d._variantStorage {
@@ -426,7 +441,7 @@ func getBridgedNSDictionaryOfRefTypesBridgedVerbatim() -> NSDictionary {
d[TestObjCKeyTy(30)] = TestObjCValueTy(1030) d[TestObjCKeyTy(30)] = TestObjCValueTy(1030)
let bridged = let bridged =
unsafeBitCast(_convertDictionaryToNSDictionary(d), to: NSDictionary.self) unsafeBitCast(convertDictionaryToNSDictionary(d), to: NSDictionary.self)
assert(isNativeNSDictionary(bridged)) assert(isNativeNSDictionary(bridged))
@@ -437,7 +452,7 @@ func getBridgedEmptyNSDictionary() -> NSDictionary {
let d = Dictionary<TestObjCKeyTy, TestObjCValueTy>() let d = Dictionary<TestObjCKeyTy, TestObjCValueTy>()
let bridged = let bridged =
unsafeBitCast(_convertDictionaryToNSDictionary(d), to: NSDictionary.self) unsafeBitCast(convertDictionaryToNSDictionary(d), to: NSDictionary.self)
assert(isNativeNSDictionary(bridged)) assert(isNativeNSDictionary(bridged))
return bridged return bridged
@@ -454,7 +469,7 @@ func getBridgedNSDictionaryOfKeyValue_ValueTypesCustomBridged(
d[TestBridgedKeyTy(i * 10)] = TestBridgedValueTy(i * 10 + 1000) d[TestBridgedKeyTy(i * 10)] = TestBridgedValueTy(i * 10 + 1000)
} }
let bridged = _convertDictionaryToNSDictionary(d) let bridged = convertDictionaryToNSDictionary(d)
assert(isNativeNSDictionary(bridged)) assert(isNativeNSDictionary(bridged))
return bridged return bridged
@@ -906,12 +921,23 @@ func getBridgedNSArrayOfRefTypeVerbatimBridged(
a.append(TestObjCValueTy(i * 10)) a.append(TestObjCValueTy(i * 10))
} }
let bridged = _convertArrayToNSArray(a) let bridged = convertArrayToNSArray(a)
assert(isNativeNSArray(bridged)) assert(isNativeNSArray(bridged))
return bridged return bridged
} }
func convertNSArrayToArray<T>(source: NSArray?) -> [T] {
if _slowPath(source == nil) { return [] }
var result: [T]?
Array._forceBridgeFromObjectiveC(source!, result: &result)
return result!
}
func convertArrayToNSArray<T>(array: [T]) -> NSArray {
return array._bridgeToObjectiveC()
}
func getBridgedNSArrayOfValueTypeCustomBridged( func getBridgedNSArrayOfValueTypeCustomBridged(
numElements numElements: Int = 3, numElements numElements: Int = 3,
capacity: Int? = nil capacity: Int? = nil
@@ -926,7 +952,7 @@ func getBridgedNSArrayOfValueTypeCustomBridged(
a.append(TestBridgedValueTy(i * 10)) a.append(TestBridgedValueTy(i * 10))
} }
let bridged = _convertArrayToNSArray(a) let bridged = convertArrayToNSArray(a)
assert(isNativeNSArray(bridged)) assert(isNativeNSArray(bridged))
return bridged return bridged

View File

@@ -226,7 +226,7 @@ func nsArrayOfStrings() -> Array<NSString> {
return src.withUnsafeBufferPointer { return src.withUnsafeBufferPointer {
let ns = NSArray(objects: UnsafePointer($0.baseAddress), count: $0.count) let ns = NSArray(objects: UnsafePointer($0.baseAddress), count: $0.count)
return _convertNSArrayToArray(ns) return ns as! [NSString]
} }
} }

View File

@@ -116,7 +116,7 @@ func testConvertToArrayOfImplicitUnwrappedClass() {
nsarr.add(X(value: 1)) nsarr.add(X(value: 1))
nsarr.add(X(value: 2)) nsarr.add(X(value: 2))
var arr: [X!] = _convertNSArrayToArray(nsarr) var arr: [X!] = nsarr as! [X!]
// CHECK: Class array count = 2 // CHECK: Class array count = 2
// CHECK: Element 0 has value X(1) // CHECK: Element 0 has value X(1)
@@ -140,7 +140,7 @@ func testConvertToArrayOfImplicitUnwrappedString() {
nsarr.add(NSString(string: "Hello")) nsarr.add(NSString(string: "Hello"))
nsarr.add(NSString(string: "World")) nsarr.add(NSString(string: "World"))
var arr: [String!] = _convertNSArrayToArray(nsarr) var arr: [String!] = nsarr as! [String!]
// CHECK: String array count = 2 // CHECK: String array count = 2
// CHECK: Element 0 has value Hello // CHECK: Element 0 has value Hello

View File

@@ -840,8 +840,8 @@ ArrayTestSuite.test("BridgedFromObjC.Nonverbatim.ArrayIsCopied") {
ArrayTestSuite.test("BridgedFromObjC.Verbatim.NSArrayIsRetained") { ArrayTestSuite.test("BridgedFromObjC.Verbatim.NSArrayIsRetained") {
let nsa = NSArray(array: getAsNSArray([ 10, 20, 30 ])) let nsa = NSArray(array: getAsNSArray([ 10, 20, 30 ]))
var a: Array<AnyObject> = _convertNSArrayToArray(nsa) var a: Array<AnyObject> = convertNSArrayToArray(nsa)
var bridgedBack: NSArray = _convertArrayToNSArray(a) var bridgedBack: NSArray = convertArrayToNSArray(a)
expectEqual( expectEqual(
unsafeBitCast(nsa, to: Int.self), unsafeBitCast(nsa, to: Int.self),
@@ -854,8 +854,8 @@ ArrayTestSuite.test("BridgedFromObjC.Verbatim.NSArrayIsRetained") {
ArrayTestSuite.test("BridgedFromObjC.Nonverbatim.NSArrayIsCopied") { ArrayTestSuite.test("BridgedFromObjC.Nonverbatim.NSArrayIsCopied") {
let nsa = NSArray(array: getAsNSArray([ 10, 20, 30 ])) let nsa = NSArray(array: getAsNSArray([ 10, 20, 30 ]))
var a: Array<TestBridgedValueTy> = _convertNSArrayToArray(nsa) var a: Array<TestBridgedValueTy> = convertNSArrayToArray(nsa)
var bridgedBack: NSArray = _convertArrayToNSArray(a) var bridgedBack: NSArray = convertArrayToNSArray(a)
expectNotEqual( expectNotEqual(
unsafeBitCast(nsa, to: Int.self), unsafeBitCast(nsa, to: Int.self),
@@ -873,12 +873,12 @@ ArrayTestSuite.test("BridgedFromObjC.Verbatim.ImmutableArrayIsRetained") {
CustomImmutableNSArray.timesCopyWithZoneWasCalled = 0 CustomImmutableNSArray.timesCopyWithZoneWasCalled = 0
CustomImmutableNSArray.timesObjectAtIndexWasCalled = 0 CustomImmutableNSArray.timesObjectAtIndexWasCalled = 0
CustomImmutableNSArray.timesCountWasCalled = 0 CustomImmutableNSArray.timesCountWasCalled = 0
let a: Array<AnyObject> = _convertNSArrayToArray(nsa) let a: Array<AnyObject> = convertNSArrayToArray(nsa)
expectEqual(1, CustomImmutableNSArray.timesCopyWithZoneWasCalled) expectEqual(1, CustomImmutableNSArray.timesCopyWithZoneWasCalled)
expectEqual(0, CustomImmutableNSArray.timesObjectAtIndexWasCalled) expectEqual(0, CustomImmutableNSArray.timesObjectAtIndexWasCalled)
expectEqual(0, CustomImmutableNSArray.timesCountWasCalled) expectEqual(0, CustomImmutableNSArray.timesCountWasCalled)
let bridgedBack: NSArray = _convertArrayToNSArray(a) let bridgedBack: NSArray = convertArrayToNSArray(a)
expectEqual( expectEqual(
unsafeBitCast(nsa, to: Int.self), unsafeBitCast(nsa, to: Int.self),
@@ -900,14 +900,14 @@ ArrayTestSuite.test("BridgedFromObjC.Nonverbatim.ImmutableArrayIsCopied") {
// FIXME: bridging shouldn't dump array contents into the autorelease pool. // FIXME: bridging shouldn't dump array contents into the autorelease pool.
autoreleasepoolIfUnoptimizedReturnAutoreleased { autoreleasepoolIfUnoptimizedReturnAutoreleased {
a = _convertNSArrayToArray(nsa) a = convertNSArrayToArray(nsa)
expectEqual(1, CustomImmutableNSArray.timesCopyWithZoneWasCalled) expectEqual(1, CustomImmutableNSArray.timesCopyWithZoneWasCalled)
expectEqual(3, CustomImmutableNSArray.timesObjectAtIndexWasCalled) expectEqual(3, CustomImmutableNSArray.timesObjectAtIndexWasCalled)
expectNotEqual(0, CustomImmutableNSArray.timesCountWasCalled) expectNotEqual(0, CustomImmutableNSArray.timesCountWasCalled)
expectEqual(3, TestBridgedValueTy.bridgeOperations) expectEqual(3, TestBridgedValueTy.bridgeOperations)
} }
let bridgedBack: NSArray = _convertArrayToNSArray(a) let bridgedBack: NSArray = convertArrayToNSArray(a)
expectNotEqual( expectNotEqual(
unsafeBitCast(nsa, to: Int.self), unsafeBitCast(nsa, to: Int.self),
@@ -1159,7 +1159,7 @@ ArrayTestSuite.test("BridgedToObjC/Verbatim/BridgeBack/Reallocate") {
let idValue2 = unsafeBitCast(v, to: UInt.self) let idValue2 = unsafeBitCast(v, to: UInt.self)
// Bridge back to native array. // Bridge back to native array.
var native: [TestObjCValueTy] = _convertNSArrayToArray(a) var native: [TestObjCValueTy] = convertNSArrayToArray(a)
native[0] = TestObjCValueTy(110) native[0] = TestObjCValueTy(110)
native[1] = TestObjCValueTy(120) native[1] = TestObjCValueTy(120)
native[2] = TestObjCValueTy(130) native[2] = TestObjCValueTy(130)
@@ -1179,7 +1179,7 @@ ArrayTestSuite.test("BridgedToObjC/Verbatim/BridgeBack/Reallocate") {
ArrayTestSuite.test("BridgedToObjC/Verbatim/BridgeBack/Adopt") { ArrayTestSuite.test("BridgedToObjC/Verbatim/BridgeBack/Adopt") {
// Bridge back to native array. // Bridge back to native array.
var native: [TestObjCValueTy] = _convertNSArrayToArray( var native: [TestObjCValueTy] = convertNSArrayToArray(
getBridgedNSArrayOfRefTypeVerbatimBridged(numElements: 3)) getBridgedNSArrayOfRefTypeVerbatimBridged(numElements: 3))
let identity1 = unsafeBitCast(native, to: UInt.self) let identity1 = unsafeBitCast(native, to: UInt.self)
@@ -1452,7 +1452,7 @@ ArrayTestSuite.test("BridgedToObjC/Custom/BridgeBack/Cast") {
let idValue2 = unsafeBitCast(v, to: UInt.self) let idValue2 = unsafeBitCast(v, to: UInt.self)
// Bridge back to native array with a cast. // Bridge back to native array with a cast.
var native: [TestObjCValueTy] = _convertNSArrayToArray(a) var native: [TestObjCValueTy] = convertNSArrayToArray(a)
native[0] = TestObjCValueTy(110) native[0] = TestObjCValueTy(110)
native[1] = TestObjCValueTy(120) native[1] = TestObjCValueTy(120)
native[2] = TestObjCValueTy(130) native[2] = TestObjCValueTy(130)
@@ -1486,7 +1486,7 @@ ArrayTestSuite.test("BridgedToObjC/Custom/BridgeBack/Reallocate") {
let idValue2 = unsafeBitCast(v, to: UInt.self) let idValue2 = unsafeBitCast(v, to: UInt.self)
// Bridge back to native array. // Bridge back to native array.
var native: [TestBridgedValueTy] = _convertNSArrayToArray(a) var native: [TestBridgedValueTy] = convertNSArrayToArray(a)
native[0] = TestBridgedValueTy(110) native[0] = TestBridgedValueTy(110)
native[1] = TestBridgedValueTy(120) native[1] = TestBridgedValueTy(120)
native[2] = TestBridgedValueTy(130) native[2] = TestBridgedValueTy(130)
@@ -1506,7 +1506,7 @@ ArrayTestSuite.test("BridgedToObjC/Custom/BridgeBack/Reallocate") {
ArrayTestSuite.test("BridgedToObjC/Custom/BridgeBack/Adopt") { ArrayTestSuite.test("BridgedToObjC/Custom/BridgeBack/Adopt") {
// Bridge back to native array. // Bridge back to native array.
var native: [TestBridgedValueTy] = _convertNSArrayToArray( var native: [TestBridgedValueTy] = convertNSArrayToArray(
getBridgedNSArrayOfValueTypeCustomBridged(numElements: 3)) getBridgedNSArrayOfValueTypeCustomBridged(numElements: 3))
let identity1 = unsafeBitCast(native, to: UInt.self) let identity1 = unsafeBitCast(native, to: UInt.self)
@@ -1530,8 +1530,8 @@ ArrayTestSuite.test("BridgedToObjC.Verbatim.RoundtripThroughSwiftArray") {
% ]: % ]:
do { do {
let nsa: NSArray = getAsImmutableNSArray([ 10, 20, 30 ]) let nsa: NSArray = getAsImmutableNSArray([ 10, 20, 30 ])
let a: ${MiddleType} = _convertNSArrayToArray(nsa) let a: ${MiddleType} = convertNSArrayToArray(nsa)
let bridgedBack = _convertArrayToNSArray(a) let bridgedBack = convertArrayToNSArray(a)
expectEqual( expectEqual(
unsafeBitCast(nsa, to: Int.self), unsafeBitCast(nsa, to: Int.self),
@@ -1561,8 +1561,8 @@ ArrayTestSuite.test("BridgedToObjC.Nonverbatim.RoundtripThroughSwiftArray") {
do { do {
TestBridgedValueTy.bridgeOperations = 0 TestBridgedValueTy.bridgeOperations = 0
let nsa: NSArray = getAsImmutableNSArray([ 10, 20, 30 ]) let nsa: NSArray = getAsImmutableNSArray([ 10, 20, 30 ])
let a: Array<TestBridgedValueTy> = _convertNSArrayToArray(nsa) let a: Array<TestBridgedValueTy> = convertNSArrayToArray(nsa)
let bridgedBack = _convertArrayToNSArray(a) let bridgedBack = convertArrayToNSArray(a)
expectEqual(3, TestBridgedValueTy.bridgeOperations) expectEqual(3, TestBridgedValueTy.bridgeOperations)
} }
do { do {

View File

@@ -1170,18 +1170,18 @@ func getAsNSMutableDictionary(d: Dictionary<Int, Int>) -> NSMutableDictionary {
func getBridgedVerbatimDictionary() -> Dictionary<NSObject, AnyObject> { func getBridgedVerbatimDictionary() -> Dictionary<NSObject, AnyObject> {
let nsd = getAsNSDictionary([ 10: 1010, 20: 1020, 30: 1030 ]) let nsd = getAsNSDictionary([ 10: 1010, 20: 1020, 30: 1030 ])
return _convertNSDictionaryToDictionary(nsd) return convertNSDictionaryToDictionary(nsd)
} }
func getBridgedVerbatimDictionary(d: Dictionary<Int, Int>) -> Dictionary<NSObject, AnyObject> { func getBridgedVerbatimDictionary(d: Dictionary<Int, Int>) -> Dictionary<NSObject, AnyObject> {
let nsd = getAsNSDictionary(d) let nsd = getAsNSDictionary(d)
return _convertNSDictionaryToDictionary(nsd) return convertNSDictionaryToDictionary(nsd)
} }
func getBridgedVerbatimDictionaryAndNSMutableDictionary() func getBridgedVerbatimDictionaryAndNSMutableDictionary()
-> (Dictionary<NSObject, AnyObject>, NSMutableDictionary) { -> (Dictionary<NSObject, AnyObject>, NSMutableDictionary) {
let nsd = getAsNSMutableDictionary([ 10: 1010, 20: 1020, 30: 1030 ]) let nsd = getAsNSMutableDictionary([ 10: 1010, 20: 1020, 30: 1030 ])
return (_convertNSDictionaryToDictionary(nsd), nsd) return (convertNSDictionaryToDictionary(nsd), nsd)
} }
func getBridgedNonverbatimDictionary() -> Dictionary<TestBridgedKeyTy, TestBridgedValueTy> { func getBridgedNonverbatimDictionary() -> Dictionary<TestBridgedKeyTy, TestBridgedValueTy> {
@@ -1202,7 +1202,7 @@ func getBridgedNonverbatimDictionaryAndNSMutableDictionary()
func getBridgedVerbatimEquatableDictionary(d: Dictionary<Int, Int>) -> Dictionary<NSObject, TestObjCEquatableValueTy> { func getBridgedVerbatimEquatableDictionary(d: Dictionary<Int, Int>) -> Dictionary<NSObject, TestObjCEquatableValueTy> {
let nsd = getAsEquatableNSDictionary(d) let nsd = getAsEquatableNSDictionary(d)
return _convertNSDictionaryToDictionary(nsd) return convertNSDictionaryToDictionary(nsd)
} }
func getBridgedNonverbatimEquatableDictionary(d: Dictionary<Int, Int>) -> Dictionary<TestBridgedKeyTy, TestBridgedEquatableValueTy> { func getBridgedNonverbatimEquatableDictionary(d: Dictionary<Int, Int>) -> Dictionary<TestBridgedKeyTy, TestBridgedEquatableValueTy> {
@@ -1219,7 +1219,7 @@ func getHugeBridgedVerbatimDictionaryHelper() -> NSDictionary {
func getHugeBridgedVerbatimDictionary() -> Dictionary<NSObject, AnyObject> { func getHugeBridgedVerbatimDictionary() -> Dictionary<NSObject, AnyObject> {
let nsd = getHugeBridgedVerbatimDictionaryHelper() let nsd = getHugeBridgedVerbatimDictionaryHelper()
return _convertNSDictionaryToDictionary(nsd) return convertNSDictionaryToDictionary(nsd)
} }
func getHugeBridgedNonverbatimDictionary() -> Dictionary<TestBridgedKeyTy, TestBridgedValueTy> { func getHugeBridgedNonverbatimDictionary() -> Dictionary<TestBridgedKeyTy, TestBridgedValueTy> {
@@ -1287,7 +1287,7 @@ class ParallelArrayDictionary : NSDictionary {
func getParallelArrayBridgedVerbatimDictionary() -> Dictionary<NSObject, AnyObject> { func getParallelArrayBridgedVerbatimDictionary() -> Dictionary<NSObject, AnyObject> {
let nsd: NSDictionary = ParallelArrayDictionary() let nsd: NSDictionary = ParallelArrayDictionary()
return _convertNSDictionaryToDictionary(nsd) return convertNSDictionaryToDictionary(nsd)
} }
func getParallelArrayBridgedNonverbatimDictionary() -> Dictionary<TestBridgedKeyTy, TestBridgedValueTy> { func getParallelArrayBridgedNonverbatimDictionary() -> Dictionary<TestBridgedKeyTy, TestBridgedValueTy> {
@@ -1400,9 +1400,9 @@ DictionaryTestSuite.test("BridgedFromObjC.Verbatim.NSDictionaryIsRetained") {
var nsd: NSDictionary = NSDictionary(dictionary: var nsd: NSDictionary = NSDictionary(dictionary:
getAsNSDictionary([ 10: 1010, 20: 1020, 30: 1030 ])) getAsNSDictionary([ 10: 1010, 20: 1020, 30: 1030 ]))
var d: [NSObject : AnyObject] = _convertNSDictionaryToDictionary(nsd) var d: [NSObject : AnyObject] = convertNSDictionaryToDictionary(nsd)
var bridgedBack: NSDictionary = _convertDictionaryToNSDictionary(d) var bridgedBack: NSDictionary = convertDictionaryToNSDictionary(d)
expectEqual( expectEqual(
unsafeBitCast(nsd, to: Int.self), unsafeBitCast(nsd, to: Int.self),
@@ -1418,9 +1418,9 @@ DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.NSDictionaryIsCopied") {
getAsNSDictionary([ 10: 1010, 20: 1020, 30: 1030 ])) getAsNSDictionary([ 10: 1010, 20: 1020, 30: 1030 ]))
var d: [TestBridgedKeyTy : TestBridgedValueTy] = var d: [TestBridgedKeyTy : TestBridgedValueTy] =
_convertNSDictionaryToDictionary(nsd) convertNSDictionaryToDictionary(nsd)
var bridgedBack: NSDictionary = _convertDictionaryToNSDictionary(d) var bridgedBack: NSDictionary = convertDictionaryToNSDictionary(d)
expectNotEqual( expectNotEqual(
unsafeBitCast(nsd, to: Int.self), unsafeBitCast(nsd, to: Int.self),
@@ -1439,13 +1439,13 @@ DictionaryTestSuite.test("BridgedFromObjC.Verbatim.ImmutableDictionaryIsRetained
CustomImmutableNSDictionary.timesObjectForKeyWasCalled = 0 CustomImmutableNSDictionary.timesObjectForKeyWasCalled = 0
CustomImmutableNSDictionary.timesKeyEnumeratorWasCalled = 0 CustomImmutableNSDictionary.timesKeyEnumeratorWasCalled = 0
CustomImmutableNSDictionary.timesCountWasCalled = 0 CustomImmutableNSDictionary.timesCountWasCalled = 0
var d: [NSObject : AnyObject] = _convertNSDictionaryToDictionary(nsd) var d: [NSObject : AnyObject] = convertNSDictionaryToDictionary(nsd)
expectEqual(1, CustomImmutableNSDictionary.timesCopyWithZoneWasCalled) expectEqual(1, CustomImmutableNSDictionary.timesCopyWithZoneWasCalled)
expectEqual(0, CustomImmutableNSDictionary.timesObjectForKeyWasCalled) expectEqual(0, CustomImmutableNSDictionary.timesObjectForKeyWasCalled)
expectEqual(0, CustomImmutableNSDictionary.timesKeyEnumeratorWasCalled) expectEqual(0, CustomImmutableNSDictionary.timesKeyEnumeratorWasCalled)
expectEqual(0, CustomImmutableNSDictionary.timesCountWasCalled) expectEqual(0, CustomImmutableNSDictionary.timesCountWasCalled)
var bridgedBack: NSDictionary = _convertDictionaryToNSDictionary(d) var bridgedBack: NSDictionary = convertDictionaryToNSDictionary(d)
expectEqual( expectEqual(
unsafeBitCast(nsd, to: Int.self), unsafeBitCast(nsd, to: Int.self),
unsafeBitCast(bridgedBack, to: Int.self)) unsafeBitCast(bridgedBack, to: Int.self))
@@ -1464,14 +1464,14 @@ DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.ImmutableDictionaryIsCopie
CustomImmutableNSDictionary.timesCountWasCalled = 0 CustomImmutableNSDictionary.timesCountWasCalled = 0
TestBridgedValueTy.bridgeOperations = 0 TestBridgedValueTy.bridgeOperations = 0
var d: [TestBridgedKeyTy : TestBridgedValueTy] = var d: [TestBridgedKeyTy : TestBridgedValueTy] =
_convertNSDictionaryToDictionary(nsd) convertNSDictionaryToDictionary(nsd)
expectEqual(0, CustomImmutableNSDictionary.timesCopyWithZoneWasCalled) expectEqual(0, CustomImmutableNSDictionary.timesCopyWithZoneWasCalled)
expectEqual(3, CustomImmutableNSDictionary.timesObjectForKeyWasCalled) expectEqual(3, CustomImmutableNSDictionary.timesObjectForKeyWasCalled)
expectEqual(1, CustomImmutableNSDictionary.timesKeyEnumeratorWasCalled) expectEqual(1, CustomImmutableNSDictionary.timesKeyEnumeratorWasCalled)
expectNotEqual(0, CustomImmutableNSDictionary.timesCountWasCalled) expectNotEqual(0, CustomImmutableNSDictionary.timesCountWasCalled)
expectEqual(3, TestBridgedValueTy.bridgeOperations) expectEqual(3, TestBridgedValueTy.bridgeOperations)
var bridgedBack: NSDictionary = _convertDictionaryToNSDictionary(d) var bridgedBack: NSDictionary = convertDictionaryToNSDictionary(d)
expectNotEqual( expectNotEqual(
unsafeBitCast(nsd, to: Int.self), unsafeBitCast(nsd, to: Int.self),
unsafeBitCast(bridgedBack, to: Int.self)) unsafeBitCast(bridgedBack, to: Int.self))
@@ -2800,7 +2800,7 @@ func getBridgedNSDictionaryOfKey_ValueTypeCustomBridged() -> NSDictionary {
d[TestBridgedKeyTy(20)] = TestObjCValueTy(1020) d[TestBridgedKeyTy(20)] = TestObjCValueTy(1020)
d[TestBridgedKeyTy(30)] = TestObjCValueTy(1030) d[TestBridgedKeyTy(30)] = TestObjCValueTy(1030)
let bridged = _convertDictionaryToNSDictionary(d) let bridged = convertDictionaryToNSDictionary(d)
assert(isNativeNSDictionary(bridged)) assert(isNativeNSDictionary(bridged))
return bridged return bridged
@@ -2830,7 +2830,7 @@ func getBridgedNSDictionaryOfValue_ValueTypeCustomBridged() -> NSDictionary {
d[TestObjCKeyTy(20)] = TestBridgedValueTy(1020) d[TestObjCKeyTy(20)] = TestBridgedValueTy(1020)
d[TestObjCKeyTy(30)] = TestBridgedValueTy(1030) d[TestObjCKeyTy(30)] = TestBridgedValueTy(1030)
let bridged = _convertDictionaryToNSDictionary(d) let bridged = convertDictionaryToNSDictionary(d)
assert(isNativeNSDictionary(bridged)) assert(isNativeNSDictionary(bridged))
return bridged return bridged
@@ -2862,9 +2862,9 @@ func getRoundtripBridgedNSDictionary() -> NSDictionary {
let nsd = NSDictionary(objects: values, forKeys: keys) let nsd = NSDictionary(objects: values, forKeys: keys)
let d: Dictionary<NSObject, AnyObject> = _convertNSDictionaryToDictionary(nsd) let d: Dictionary<NSObject, AnyObject> = convertNSDictionaryToDictionary(nsd)
let bridgedBack = _convertDictionaryToNSDictionary(d) let bridgedBack = convertDictionaryToNSDictionary(d)
assert(isCocoaNSDictionary(bridgedBack)) assert(isCocoaNSDictionary(bridgedBack))
// FIXME: this should be true. // FIXME: this should be true.
//assert(unsafeBitCast(nsd, Int.self) == unsafeBitCast(bridgedBack, Int.self)) //assert(unsafeBitCast(nsd, Int.self) == unsafeBitCast(bridgedBack, Int.self))

View File

@@ -135,7 +135,7 @@ func isCocoaNSSet(s: NSSet) -> Bool {
func getBridgedEmptyNSSet() -> NSSet { func getBridgedEmptyNSSet() -> NSSet {
let s = Set<TestObjCKeyTy>() let s = Set<TestObjCKeyTy>()
let bridged = unsafeBitCast(_convertSetToNSSet(s), to: NSSet.self) let bridged = unsafeBitCast(convertSetToNSSet(s), to: NSSet.self)
expectTrue(isNativeNSSet(bridged)) expectTrue(isNativeNSSet(bridged))
return bridged return bridged
@@ -170,11 +170,22 @@ func getAsNSMutableSet(members: [Int] = [1010, 2020, 3030]) -> NSMutableSet {
return NSMutableSet(array: nsArray as [AnyObject]) return NSMutableSet(array: nsArray as [AnyObject])
} }
public func convertSetToNSSet<T>(s: Set<T>) -> NSSet {
return s._bridgeToObjectiveC()
}
public func convertNSSetToSet<T : Hashable>(s: NSSet?) -> Set<T> {
if _slowPath(s == nil) { return [] }
var result: Set<T>?
Set._forceBridgeFromObjectiveC(s!, result: &result)
return result!
}
/// Get a Set<NSObject> (Set<TestObjCKeyTy>) backed by Cocoa storage /// Get a Set<NSObject> (Set<TestObjCKeyTy>) backed by Cocoa storage
func getBridgedVerbatimSet(members: [Int] = [1010, 2020, 3030]) func getBridgedVerbatimSet(members: [Int] = [1010, 2020, 3030])
-> Set<NSObject> { -> Set<NSObject> {
let nss = getAsNSSet(members) let nss = getAsNSSet(members)
let result: Set<NSObject> = _convertNSSetToSet(nss) let result: Set<NSObject> = convertNSSetToSet(nss)
expectTrue(isCocoaSet(result)) expectTrue(isCocoaSet(result))
return result return result
} }
@@ -190,7 +201,7 @@ func getNativeBridgedVerbatimSet(members: [Int] = [1010, 2020, 3030]) ->
/// Get a Set<NSObject> (Set<TestObjCKeyTy>) backed by Cocoa storage /// Get a Set<NSObject> (Set<TestObjCKeyTy>) backed by Cocoa storage
func getHugeBridgedVerbatimSet() -> Set<NSObject> { func getHugeBridgedVerbatimSet() -> Set<NSObject> {
let nss = getAsNSSet(hugeNumberArray) let nss = getAsNSSet(hugeNumberArray)
let result: Set<NSObject> = _convertNSSetToSet(nss) let result: Set<NSObject> = convertNSSetToSet(nss)
expectTrue(isCocoaSet(result)) expectTrue(isCocoaSet(result))
return result return result
} }
@@ -218,7 +229,7 @@ func getHugeBridgedNonverbatimSet() -> Set<TestBridgedKeyTy> {
func getBridgedVerbatimSetAndNSMutableSet() -> (Set<NSObject>, NSMutableSet) { func getBridgedVerbatimSetAndNSMutableSet() -> (Set<NSObject>, NSMutableSet) {
let nss = getAsNSMutableSet() let nss = getAsNSMutableSet()
return (_convertNSSetToSet(nss), nss) return (convertNSSetToSet(nss), nss)
} }
func getBridgedNonverbatimSetAndNSMutableSet() func getBridgedNonverbatimSetAndNSMutableSet()
@@ -236,7 +247,7 @@ func getBridgedNSSetOfRefTypesBridgedVerbatim() -> NSSet {
s.insert(TestObjCKeyTy(3030)) s.insert(TestObjCKeyTy(3030))
let bridged = let bridged =
unsafeBitCast(_convertSetToNSSet(s), to: NSSet.self) unsafeBitCast(convertSetToNSSet(s), to: NSSet.self)
expectTrue(isNativeNSSet(bridged)) expectTrue(isNativeNSSet(bridged))
@@ -253,7 +264,7 @@ func getBridgedNSSet_ValueTypesCustomBridged(
s.insert(TestBridgedKeyTy(i * 1000 + i * 10)) s.insert(TestBridgedKeyTy(i * 1000 + i * 10))
} }
let bridged = _convertSetToNSSet(s) let bridged = convertSetToNSSet(s)
expectTrue(isNativeNSSet(bridged)) expectTrue(isNativeNSSet(bridged))
return bridged return bridged
@@ -267,9 +278,9 @@ func getRoundtripBridgedNSSet() -> NSSet {
let nss = NSSet(array: items as [AnyObject]) let nss = NSSet(array: items as [AnyObject])
let s: Set<NSObject> = _convertNSSetToSet(nss) let s: Set<NSObject> = convertNSSetToSet(nss)
let bridgedBack = _convertSetToNSSet(s) let bridgedBack = convertSetToNSSet(s)
expectTrue(isCocoaNSSet(bridgedBack)) expectTrue(isCocoaNSSet(bridgedBack))
// FIXME: this should be true. // FIXME: this should be true.
//expectTrue(unsafeBitCast(nsd, to: Int.self) == unsafeBitCast(bridgedBack, to: Int.self)) //expectTrue(unsafeBitCast(nsd, to: Int.self) == unsafeBitCast(bridgedBack, to: Int.self))
@@ -285,7 +296,7 @@ func getBridgedNSSet_MemberTypesCustomBridged() -> NSSet {
s.insert(TestBridgedKeyTy(2020)) s.insert(TestBridgedKeyTy(2020))
s.insert(TestBridgedKeyTy(3030)) s.insert(TestBridgedKeyTy(3030))
let bridged = _convertSetToNSSet(s) let bridged = convertSetToNSSet(s)
expectTrue(isNativeNSSet(bridged)) expectTrue(isNativeNSSet(bridged))
return bridged return bridged
@@ -1231,9 +1242,9 @@ SetTestSuite.test("BridgedFromObjC.Nonverbatim.SetIsCopied") {
SetTestSuite.test("BridgedFromObjC.Verbatim.NSSetIsRetained") { SetTestSuite.test("BridgedFromObjC.Verbatim.NSSetIsRetained") {
var nss: NSSet = NSSet(set: getAsNSSet([ 1010, 1020, 1030 ])) var nss: NSSet = NSSet(set: getAsNSSet([ 1010, 1020, 1030 ]))
var s: Set<NSObject> = _convertNSSetToSet(nss) var s: Set<NSObject> = convertNSSetToSet(nss)
var bridgedBack: NSSet = _convertSetToNSSet(s) var bridgedBack: NSSet = convertSetToNSSet(s)
expectEqual( expectEqual(
unsafeBitCast(nss, to: Int.self), unsafeBitCast(nss, to: Int.self),
@@ -1247,9 +1258,9 @@ SetTestSuite.test("BridgedFromObjC.Verbatim.NSSetIsRetained") {
SetTestSuite.test("BridgedFromObjC.Nonverbatim.NSSetIsCopied") { SetTestSuite.test("BridgedFromObjC.Nonverbatim.NSSetIsCopied") {
var nss: NSSet = NSSet(set: getAsNSSet([ 1010, 1020, 1030 ])) var nss: NSSet = NSSet(set: getAsNSSet([ 1010, 1020, 1030 ]))
var s: Set<TestBridgedKeyTy> = _convertNSSetToSet(nss) var s: Set<TestBridgedKeyTy> = convertNSSetToSet(nss)
var bridgedBack: NSSet = _convertSetToNSSet(s) var bridgedBack: NSSet = convertSetToNSSet(s)
expectNotEqual( expectNotEqual(
unsafeBitCast(nss, to: Int.self), unsafeBitCast(nss, to: Int.self),
@@ -1268,13 +1279,13 @@ SetTestSuite.test("BridgedFromObjC.Verbatim.ImmutableSetIsRetained") {
CustomImmutableNSSet.timesMemberWasCalled = 0 CustomImmutableNSSet.timesMemberWasCalled = 0
CustomImmutableNSSet.timesObjectEnumeratorWasCalled = 0 CustomImmutableNSSet.timesObjectEnumeratorWasCalled = 0
CustomImmutableNSSet.timesCountWasCalled = 0 CustomImmutableNSSet.timesCountWasCalled = 0
var s: Set<NSObject> = _convertNSSetToSet(nss) var s: Set<NSObject> = convertNSSetToSet(nss)
expectEqual(1, CustomImmutableNSSet.timesCopyWithZoneWasCalled) expectEqual(1, CustomImmutableNSSet.timesCopyWithZoneWasCalled)
expectEqual(0, CustomImmutableNSSet.timesMemberWasCalled) expectEqual(0, CustomImmutableNSSet.timesMemberWasCalled)
expectEqual(0, CustomImmutableNSSet.timesObjectEnumeratorWasCalled) expectEqual(0, CustomImmutableNSSet.timesObjectEnumeratorWasCalled)
expectEqual(0, CustomImmutableNSSet.timesCountWasCalled) expectEqual(0, CustomImmutableNSSet.timesCountWasCalled)
var bridgedBack: NSSet = _convertSetToNSSet(s) var bridgedBack: NSSet = convertSetToNSSet(s)
expectEqual( expectEqual(
unsafeBitCast(nss, to: Int.self), unsafeBitCast(nss, to: Int.self),
unsafeBitCast(bridgedBack, to: Int.self)) unsafeBitCast(bridgedBack, to: Int.self))
@@ -1291,13 +1302,13 @@ SetTestSuite.test("BridgedFromObjC.Nonverbatim.ImmutableSetIsCopied") {
CustomImmutableNSSet.timesMemberWasCalled = 0 CustomImmutableNSSet.timesMemberWasCalled = 0
CustomImmutableNSSet.timesObjectEnumeratorWasCalled = 0 CustomImmutableNSSet.timesObjectEnumeratorWasCalled = 0
CustomImmutableNSSet.timesCountWasCalled = 0 CustomImmutableNSSet.timesCountWasCalled = 0
var s: Set<TestBridgedKeyTy> = _convertNSSetToSet(nss) var s: Set<TestBridgedKeyTy> = convertNSSetToSet(nss)
expectEqual(0, CustomImmutableNSSet.timesCopyWithZoneWasCalled) expectEqual(0, CustomImmutableNSSet.timesCopyWithZoneWasCalled)
expectEqual(0, CustomImmutableNSSet.timesMemberWasCalled) expectEqual(0, CustomImmutableNSSet.timesMemberWasCalled)
expectEqual(1, CustomImmutableNSSet.timesObjectEnumeratorWasCalled) expectEqual(1, CustomImmutableNSSet.timesObjectEnumeratorWasCalled)
expectNotEqual(0, CustomImmutableNSSet.timesCountWasCalled) expectNotEqual(0, CustomImmutableNSSet.timesCountWasCalled)
var bridgedBack: NSSet = _convertSetToNSSet(s) var bridgedBack: NSSet = convertSetToNSSet(s)
expectNotEqual( expectNotEqual(
unsafeBitCast(nss, to: Int.self), unsafeBitCast(nss, to: Int.self),
unsafeBitCast(bridgedBack, to: Int.self)) unsafeBitCast(bridgedBack, to: Int.self))