Substring conforms to _ObjectiveCBridgeable

This commit is contained in:
Max Moiseev
2017-02-22 17:11:13 -08:00
parent 42703c9978
commit 457b8fcdb2

View File

@@ -60,4 +60,37 @@ extension String : _ObjectiveCBridgeable {
}
}
extension Substring : _ObjectiveCBridgeable {
@_semantics("convertToObjectiveC")
public func _bridgeToObjectiveC() -> NSString {
return String(self)._bridgeToObjectiveC()
}
public static func _forceBridgeFromObjectiveC(
_ x: NSString,
result: inout Substring?
) {
let s = String(x)
result = Substring(_base: s, s.startIndex ..< s.endIndex)
}
public static func _conditionallyBridgeFromObjectiveC(
_ x: NSString,
result: inout Substring?
) -> Bool {
self._forceBridgeFromObjectiveC(x, result: &result)
return result != nil
}
public static func _unconditionallyBridgeFromObjectiveC(
_ source: NSString?
) -> Substring {
// `nil` has historically been used as a stand-in for an empty
// string; map it to an empty substring.
if _slowPath(source == nil) { return Substring() }
let s = String(source!)
return Substring(_base: s, s.startIndex ..< s.endIndex)
}
}
extension String: CVarArg {}