Initializer

init(_:)

Creates a new integer value from the given string. 与えられた文字列から新しい整数値を作成します。

Declaration 宣言

init?(_ description: String)

Parameters パラメータ

description

The ASCII representation of a number. ある数のASCII表現。

Discussion 解説

The string passed as description may begin with a plus or minus sign character (+ or -), followed by one or more numeric digits (0-9). descriptionとして渡される文字列は、プラスまたはマイナス符号文字(+または-)で始まり、1つ以上の数値のアラビア数字(0-9)が続くことがあります。


let x = Int("123")
// x == 123

If description is in an invalid format, or if the value it denotes in base 10 is not representable, the result is nil. For example, the following conversions result in nil: descriptionが無効な形式になっているならば、またはそれが底10で示す値が表現可能でないならば、結果はnilです。例えば、次の変換はnilという結果になります:


Int(" 100")                       // Includes whitespace
Int("21-50")                      // Invalid format
Int("ff6600")                     // Characters out of bounds
Int("10000000000000000000000000") // Out of range