Generic Initializer

init(_:)

Creates a new instance from the given integer.

Required.

Declaration

init<T>(_ source: T) where T : BinaryInteger

Parameters

source

An integer to convert. source must be representable in this type.

Discussion

If the value passed as source is not representable in this type, a runtime error may occur.

let x = -500 as Int
let y = Int32(x)
// y == -500

// -500 is not representable as a 'UInt32' instance
let z = UInt32(x)
// Error