[swift-evolution] [Draft] Abolish IUO type
xenadu at gmail.com
Wed Mar 16 20:16:22 CDT 2016
> On Mar 15, 2016, at 10:03 PM, Chris Willmore via swift-evolution <swift-evolution at swift.org> wrote:
> Hi, swift-evolution,
> Some colleagues and I have been working on a proposal <https://github.com/cwillmor/swift-evolution/blob/master/proposals/0000-abolish-iuo.md> to remove the ImplicitlyUnwrappedOptional type from Swift and replace it with an IUO decl attribute. Please have a look; I would greatly appreciate any comments you have before I push this proposal forward.
> https://github.com/cwillmor/swift-evolution/blob/master/proposals/0000-abolish-iuo.md <https://github.com/cwillmor/swift-evolution/blob/master/proposals/0000-abolish-iuo.md>
> — Chris Willmore
> Abolish ImplicitlyUnwrappedOptional type
> Proposal: SE-NNNN
> Author: Chris Willmore <http://github.com/cwillmor>
> Status: TBD
> Review Manager: TBD
> This proposal seeks to remove the ImplicitlyUnwrappedOptional type from the Swift type system and replace it with an IUO attribute on declarations. Appending ! to the type of a Swift declaration will give it optional type and annotate the declaration with an attribute stating that it (or, in the case of a function, the return value of its application) may be implicitly unwrapped.
Let me play devil’s advocate: why not just get rid of implicit unwrapping entirely?
Apple’s Objective-C APIs have had plenty of time to be audited by now. Anything not annotated can be assumed to be optional (which is the safest bet).
The only case where IUOs are necessary is when you can’t cram something into the Swift initialization patterns (view controllers with outlets are the primary example). Having an attribute to suppress the compiler errors about failing to initialize outlet properties solves that problem (and any similar initialization problem) while limiting the scope. For example:
@noinit @IBOutlet var view: UIView
I’ve gotten into the habit of treating `!` as if it were `?` anyway and it hasn’t steered me wrong yet.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution