protocol ExpressibleByIntegerLiteral
Inheritance | View Protocol Hierarchy → |
---|---|
Associated Types | |
Import | import Swift |
Initializers
Creates an instance initialized to the specified integer value.
Do not call this initializer directly. Instead, initialize a variable or constant using an integer literal. For example:
let x = 23
In this example, the assignment to the x
constant calls this integer
literal initializer behind the scenes.
value
: The value to create.
Declaration
init(integerLiteral value: Self.IntegerLiteralType)
A type that can be initialized with an integer literal.
The standard library integer and floating-point types, such as
Int
andDouble
, conform to theExpressibleByIntegerLiteral
protocol. You can initialize a variable or constant of any of these types by assigning an integer literal.Conforming to ExpressibleByIntegerLiteral
To add
ExpressibleByIntegerLiteral
conformance to your custom type, implement the required initializer.