Skip to content

[4.1] Revert removal of some extensions on ImplicitlyUnwrappedOptional<T> #13976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions stdlib/public/core/ImplicitlyUnwrappedOptional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,48 @@ public enum ImplicitlyUnwrappedOptional<Wrapped> : ExpressibleByNilLiteral {
self = .none
}
}

#if _runtime(_ObjC)
extension ImplicitlyUnwrappedOptional : _ObjectiveCBridgeable {
@_inlineable // FIXME(sil-serialize-all)
public func _bridgeToObjectiveC() -> AnyObject {
switch self {
case .none:
_preconditionFailure("Attempt to bridge an implicitly unwrapped optional containing nil")

case .some(let x):
return Swift._bridgeAnythingToObjectiveC(x)
}
}

@_inlineable // FIXME(sil-serialize-all)
public static func _forceBridgeFromObjectiveC(
_ x: AnyObject,
result: inout ImplicitlyUnwrappedOptional<Wrapped>?
) {
result = Swift._forceBridgeFromObjectiveC(x, Wrapped.self)
}

@_inlineable // FIXME(sil-serialize-all)
public static func _conditionallyBridgeFromObjectiveC(
_ x: AnyObject,
result: inout ImplicitlyUnwrappedOptional<Wrapped>?
) -> Bool {
let bridged: Wrapped? =
Swift._conditionallyBridgeFromObjectiveC(x, Wrapped.self)
if let value = bridged {
result = value
}

return false
}

@_inlineable // FIXME(sil-serialize-all)
public static func _unconditionallyBridgeFromObjectiveC(_ source: AnyObject?)
-> Wrapped! {
var result: ImplicitlyUnwrappedOptional<Wrapped>?
_forceBridgeFromObjectiveC(source!, result: &result)
return result!
}
}
#endif