> On 14 Jul 2017, at 2:36 pm, Robert Bennett via swift-evolution 
> <[email protected]> wrote:
> 
> When writing Swift code, it is not uncommon to forget to unwrap optionals. 
> The compiler will offer a fixit, telling you you must insert either a ? or a 
> !. However, when you accept the fixit, ! is inserted (at least, it is for me 
> in Xcode 8.3).
When you treat an optional as non-optional, the compiler has no way to do a 
fixit that would appropriately handle the optional. Felix made a good example. 
The only direct fixit would be a force unwrap. If you used “?” then your 
non-optional use would turn into an optional and your parameter would generally 
be non-optional. The fixit is just explicitly doing what you implicitly 
expected it to do.

> 
> Ideally the fixit would default to ? because this is the preferred option; ! 
> is often a sign of non-Swifty code and does not interact well with idiomatic 
> Swift constructs such as if-let-(as?), guard-let-(as?)-else, etc. Also I 
> think it’s safe to say that fixits should not err on the side of crashing at 
> runtime.

" ! is often a sign of non-Swifty code “
I would strongly challenge this assumption. Many core team members have 
commented about appropriate uses of the ! operator. It shouldn’t be used 
lightly, but it’s there for a reason and it most definitely isn’t “non-swifty”.


> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to