[swift-evolution] [Draft] Abolish IUO type

Russ Bishop 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>
> 
> Thanks,
> — 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.
> 
>  <https://github.com/cwillmor/swift-evolution/blob/89971a8162eba3aeb238d47772cda295a02cc585/proposals/0000-abolish-iuo.md#motivation>Motivation
> 


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.


Russ

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160316/db7f311d/attachment.html>


More information about the swift-evolution mailing list