Protocolswift 6.0.1Swift
ExpressibleByIntegerLiteral
A type that can be initialized with an integer literal.
protocol ExpressibleByIntegerLiteral
The standard library integer and floating-point types, such as Int
and Double
, conform to the ExpressibleByIntegerLiteral
protocol. You can initialize a variable or constant of any of these types by assigning an integer literal.
// Type inferred as 'Int'
let cookieCount = 12
// An array of 'Int'
let chipsPerCookie = [21, 22, 25, 23, 24, 19]
// A floating-point value initialized using an integer literal
let redPercentage: Double = 1
// redPercentage == 1.0
Conforming to ExpressibleByIntegerLiteral
To add ExpressibleByIntegerLiteral
conformance to your custom type, implement the required initializer.
Requirements
Type members
associatedtype IntegerLiteralType
A type that represents an integer literal.
init(integerLiteral: Self.IntegerLiteralType
) Creates an instance initialized to the specified integer value.
Citizens in Swift
Subtypes
protocol BinaryFloatingPoint
A radix-2 (binary) floating-point type.
protocol BinaryInteger
An integer type with a binary representation.
protocol FixedWidthInteger
An integer type that uses a fixed size for every instance.
protocol FloatingPoint
A floating-point numeric type.
protocol Numeric
A type with values that support multiplication.
protocol SignedInteger
An integer type that can represent both positive and negative values.
protocol SignedNumeric
A numeric type with a negation operation.
protocol UnsignedInteger
An integer type that can represent only nonnegative values.
Citizens in Swift
where Self:_ExpressibleByBuiltinIntegerLiteral
Type members
Extension in RealModule
Subtypes
protocol AlgebraicField
A type modeling an algebraic field. Refines the
SignedNumeric
protocol, adding division.protocol Real
A type that models the real numbers.