Returns the given integer as the equivalent value in a different integer
type.
The numericCast(_:) function traps on overflow in -O and -Onone
builds.
You can use numericCast(_:) to convert a value when the destination type
can be inferred from the context. In the following example, the
random(in:) function uses numericCast(_:) twice to convert the
argument and return value of the arc4random_uniform(_:) function to the
appropriate type.
Returns the given integer as the equivalent value in a different integer type.
The
numericCast(_:)
function traps on overflow in-O
and-Onone
builds.You can use
numericCast(_:)
to convert a value when the destination type can be inferred from the context. In the following example, therandom(in:)
function usesnumericCast(_:)
twice to convert the argument and return value of thearc4random_uniform(_:)
function to the appropriate type.x
: The integer to convert, and instance of typeT
. Returns: The value ofx
converted to typeU
.Declaration
func
numericCast
<
T
,
U
>
(
_
x
:
T
) -
>
U
where
T
:
BinaryInteger
,
U
:
BinaryInteger