The first value to add. 加算する第1の値。
+(_:_:)
Availability
- iOS 8.0+
- iPadOS 8.0+
- macOS 10.10+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
- Xcode 9.0+
Technology
- Swift Standard Library Swift標準ライブラリ
Declaration 宣言
Parameters パラメータ
lhs
rhs
The second value to add. 加算する第2の値。
Discussion 解説
The addition operator (+
) calculates the sum of its two arguments. For example:
加算演算子(+
)は、それの2つの引数の合計を計算します。例えば:
1 + 2 // 3
-10 + 15 // 5
-15 + -5 // -20
21.5 + 3.25 // 24.75
You cannot use +
with arguments of different types. To add values of different types, convert one of the values to the other value’s type.
あなたは、+
をそれぞれが異なる型である引数で使うことはできません。異なる型の値を加算するには、それらの値の一方を、他方の値の型へと変換してください。
let x: Int8 = 21
let y: Int = 1000000
Int(x) + y // 1000021
The sum of the two arguments must be representable in the arguments’ type. In the following example, the result of 21 + 120
is greater than the maximum representable Int8
value:
2つの引数の合計は、引数の持つ型において表現可能でなければなりません。以下の例において、21 + 120
の結果は、最大限表現可能なInt8
値より大きいです:
x + 120 // Overflow error
Note 注意
Overflow checking is not performed in -Ounchecked
builds.
オーバーフロー検査は、-Ounchecked
ビルドでは実行されません。
If you want to opt out of overflow checking and wrap the result in case of any overflow, use the overflow addition operator (&+
).
あなたがオーバーフロー検査を取りやめて、あらゆるオーバーフローの場合に結果をラップしたいならば、オーバーフロー加算演算子(&+
)を使ってください。
x &+ 120 // -115
Relationships 関係
From Protocol 由来プロトコル
See Also 参照
Arithmetic 算術
static func - (Int, Int) -> Int
static func * (Int, Int) -> Int
static func / (Int, Int) -> Int
static func % (Int, Int) -> Int