[swift-evolution] Proposal: disallow nil in favor of .None

David Waite david at alkaline-solutions.com
Sun Apr 10 17:15:51 CDT 2016


Paul,

Basically, nil is a literal and not a shortcut or alias for Optional.none.

Types which implement NilLiteralConvertible can have a new instance initialized by the ‘nil’ literal. There is an initializer on Optional that is used to generate an Optional.none in response to a nil literal when expecting an Optional type.

There are also similar Convertible protocols Boolean, String, Array, Dictionary, Floating point and Integer literals.

The use cases for the nil literal within the standard library are decreasing. However, I have used it for a few other rare cases (most notably a native JSON library).

-DW

> On Apr 10, 2016, at 2:53 PM, Paul Young via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Please forgive me if this has already been discussed, but I couldn't find reference to it anywhere.
> 
> My proposal is pretty simple – disallow the use of `nil` and require the use of `.None` instead.
> 
> I would like to understand if there are any technical (or otherwise) reasons for `nil` to remain, or if it simply a remnant of interop with Objective-C.
> 
> Thanks,
> 
> Paul
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 496 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160410/21dce9b1/attachment.sig>


More information about the swift-evolution mailing list