Skip to content

Commit a3a8c6b

Browse files
authored
Merge pull request #13976 from rudkx/revert-IUO-extension-removal
[4.1] Revert removal of some extensions on ImplicitlyUnwrappedOptional<T>
2 parents 7244fea + 8d20cb2 commit a3a8c6b

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

stdlib/public/core/ImplicitlyUnwrappedOptional.swift

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,48 @@ public enum ImplicitlyUnwrappedOptional<Wrapped> : ExpressibleByNilLiteral {
4949
self = .none
5050
}
5151
}
52+
53+
#if _runtime(_ObjC)
54+
extension ImplicitlyUnwrappedOptional : _ObjectiveCBridgeable {
55+
@_inlineable // FIXME(sil-serialize-all)
56+
public func _bridgeToObjectiveC() -> AnyObject {
57+
switch self {
58+
case .none:
59+
_preconditionFailure("Attempt to bridge an implicitly unwrapped optional containing nil")
60+
61+
case .some(let x):
62+
return Swift._bridgeAnythingToObjectiveC(x)
63+
}
64+
}
65+
66+
@_inlineable // FIXME(sil-serialize-all)
67+
public static func _forceBridgeFromObjectiveC(
68+
_ x: AnyObject,
69+
result: inout ImplicitlyUnwrappedOptional<Wrapped>?
70+
) {
71+
result = Swift._forceBridgeFromObjectiveC(x, Wrapped.self)
72+
}
73+
74+
@_inlineable // FIXME(sil-serialize-all)
75+
public static func _conditionallyBridgeFromObjectiveC(
76+
_ x: AnyObject,
77+
result: inout ImplicitlyUnwrappedOptional<Wrapped>?
78+
) -> Bool {
79+
let bridged: Wrapped? =
80+
Swift._conditionallyBridgeFromObjectiveC(x, Wrapped.self)
81+
if let value = bridged {
82+
result = value
83+
}
84+
85+
return false
86+
}
87+
88+
@_inlineable // FIXME(sil-serialize-all)
89+
public static func _unconditionallyBridgeFromObjectiveC(_ source: AnyObject?)
90+
-> Wrapped! {
91+
var result: ImplicitlyUnwrappedOptional<Wrapped>?
92+
_forceBridgeFromObjectiveC(source!, result: &result)
93+
return result!
94+
}
95+
}
96+
#endif

0 commit comments

Comments
 (0)