[swift-evolution] [Review] SE-0140: Bridge Optional As Its Payload Or NSNull

Joe Groff jgroff at apple.com
Wed Sep 7 11:09:36 CDT 2016

> On Sep 7, 2016, at 12:52 AM, David Hart via swift-evolution <swift-evolution at swift.org> wrote:
> I’’ve been migrating a project to Swift 3 and a the piece of code below did not require any modification but had wildly different results:
> let myView = viewController.view
> superview.addConstraints([
>     NSLayoutConstraint(
>         item: myView, attribute: .left,
>         relatedBy: .equal,
>         toItem: superview, attribute: .left,
>         multiplier: 1, constant: 0)
> ])
> UIViewController’s view property is typed as UIView! so myView’s type is inferred to UIView? in Swift 3 (previous inferred as UIView! in Swift 2). This will crash in Swift 3 (not in Swift 2), because I think that myView’s optional value is not bridged to the wrapped value in Objective-C when passed to NSLayoutConstraint. Can somebody confirm that this proposal fixes this issue?

The correct behavior would end up falling out with this proposal, yeah, though it would still arguably be more correct for us to force-unwrap IUOs before sticking them in a non-optional Any, instead of putting the wrapped Optional into the Any.


More information about the swift-evolution mailing list