“Hidden” Functions

One of the things that bugs me about Swift is how it can be difficult to find documentation on some of the global functions. Take, for example numericCast(_:):

Convert x to type U, trapping on overflow in -Onone and -O builds.

Typically used to do conversion to any contextually-deduced integer type

Neat. Wait, what?

Huh. Okay, so maybe this will work to convert the UInt16 that I chose for my latest CoreData project:

That’s it. It’s context aware, so the compiler will figure out the type (as long as theValue specifies its type explicitly), and there are four versions (one for each combination of Signed vs Unsigned integer).