Let it crash

The two languages are very similar in this regard, there's ?: "Elvis" operator that matches Swift's ??, and !! matching Swift's !


The difference between Kotlin's !! and Swift's ! is that the first is catchable by the standard try/catch machinery, which is impossible with Swift's do/try/catch machinery without a seriously breaking change of making ! throwing (which is a no go as it would invalidate pretty much all Swift code written in the last 9 years) or until some new type of "unchecked" exceptions are introduced (which I don't see coming). It is possible to catch ! unwraps using signals see the relevant thread although I'd use it only as a last resort approach.

3 Likes