[swift-evolution] Brainstorming: New operator type - chaining

Joseph Lord joseph at human-friendly.com
Sun Jan 31 04:09:08 CST 2016


On 31/01/2016 02:51, Howard Lovatt via swift-evolution wrote:
> I am probably completely mis-understanding what you want. Your 1st
> example, isn't it equivalent to:
>
>      foo!.bar()
>

I probably wasn't very clear. The 1st example is equivalent to the force 
unwrap but only in debug builds. In release builds it becomes equivalent to:

foo?.bar()

This gives the strict checking in development and allows you to check 
that assumptions of non-nilness are correct but still provides compiler 
proven nil safe handling in production.

I already use a similar approach for nil-coalescing in places where that 
is a suitable option: 
http://blog.human-friendly.com/theanswer-equals-maybeanswer-or-a-good-alternative

Joseph


More information about the swift-evolution mailing list