プロトコル


ExpressibleByIntegerLiteral


整数リテラルで初期化できる型。


iOS 8.0+ iPadOS 8.0+ Mac Catalyst 13.0+ macOS 10.10+ tvOS 9.0

visionOS 1.0+ watchOS 2.0+

protocol ExpressibleByIntegerLiteral




概観


標準ライブラリの整数型と浮動小数点型(Int、Double など)は、ExpressibleByIntegerLiteral プロトコルに準拠しています。これらの型全ての変数または定数は、整数リテラルを代入することで初期化できます。


  1. // Type inferred as 'Int'
  2. let cookieCount = 12
  3. // An array of 'Int'
  4. let chipsPerCookie = [21, 22, 25, 23, 24, 19]
  5. // A floating-point value initialized using an integer literal
  6. let redPercentage: Double = 1
  7. // redPercentage == 1.0

ExpressibleByIntegerLiteral への準拠


カスタムの型に ExpressibleByIntegerLiteral の準拠を追加するには、必要なイニシャライザを実装します。





トピックス


関連型


associatedtype IntegerLiteralType : _ExpressibleByBuiltinIntegerLiteral

整数リテラルを表す型。

必須



イニシャライザ


init(integerLiteral: Self.IntegerLiteralType)

指定された整数値に初期化されたインスタンスを作成します。

必須 デフォルトの実装が提供されます。





関連


以下による継承


BinaryFloatingPoint

BinaryInteger

FixedWidthInteger

FloatingPoint

SignedInteger

SignedNumeric

UnsignedInteger



準拠型


Double

Float

Float16

Float80

Int

Int128

Int16

Int32

Int64

Int8

UInt

UInt128

UInt16

UInt32

UInt64

UInt8





以下も見よ


値リテラル


protocol ExpressibleByFloatLiteral

浮動小数点リテラルで初期化できる型。


protocol ExpressibleByBooleanLiteral

ブール値リテラル true および false で初期化できる型。


protocol ExpressibleByNilLiteral

nil リテラル nil を使用して初期化できる型。


struct StaticBigInt

変更できない任意精度の符号付き整数。














トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ