Required Initializerswift 6.0.1Swift

    init(_:)

    Creates a new instance from the given integer.

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

    Parameters

    source

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

    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

    Other requirements

    View members

    Hide members

    This section is hidden by default because it contains too many (33) members.

    Type members

    Instance members

    Citizens in Swift

    Default implementations

    • init<T>(T)

      Creates a new instance from the given integer.

    • init<T>(T)

      Creates a new instance from the given integer.

    • init?(String)

      Creates a new integer value from the given string.

    • init<T>(T)

      Creates an integer from the given floating-point value, rounding toward zero. Any fractional part of the value passed as source is removed.

    Extension in BitCollections

    Default implementations

    • init(BitArray)

      Creates a new instance from the bits in the given bit array, if the corresponding integer value can be represented exactly. If the value is not representable exactly, then a runtime error will occur.