操作符
+(_:
+(_:_:)
将两个值相加并产生它们的总和。
必需的。
声明
override static func + (lhs: Self, rhs: Self) -> Self
参数
lhs
要添加的第一个值。
rhs
要添加的第二个值。
详述
加法运算符 (+
) 计算其两个参数的总和。例如:
1 + 2 // 3
-10 + 15 // 5
-15 + -5 // -20
21.5 + 3.25 // 24.75
您不能将+
与不同类型的参数一起使用。要添加不同类型的值,请将其中一个值转换为另一个值的类型。
let x: Int8 = 21
let y: Int = 1000000
Int(x) + y // 1000021
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相关用法
- Swift BinaryInteger quotientAndRemainder(dividingBy:)用法及代码示例
- Swift BinaryInteger trailingZeroBitCount用法及代码示例
- Swift BinaryInteger init(clamping:)用法及代码示例
- Swift BinaryInteger <<=(_:_:)用法及代码示例
- Swift BinaryInteger !=(_:_:)用法及代码示例
- Swift BinaryInteger /(_:_:)用法及代码示例
- Swift BinaryInteger init(truncatingIfNeeded:)用法及代码示例
- Swift BinaryInteger ==(_:_:)用法及代码示例
- Swift BinaryInteger init(_:)用法及代码示例
- Swift BinaryInteger %=(_:_:)用法及代码示例
- Swift BinaryInteger &=(_:_:)用法及代码示例
- Swift BinaryInteger |(_:_:)用法及代码示例
- Swift BinaryInteger &(_:_:)用法及代码示例
- Swift BinaryInteger ^=(_:_:)用法及代码示例
- Swift BinaryInteger ^(_:_:)用法及代码示例
- Swift BinaryInteger %(_:_:)用法及代码示例
- Swift BinaryInteger *(_:_:)用法及代码示例
- Swift BinaryInteger -(_:_:)用法及代码示例
- Swift BinaryInteger /=(_:_:)用法及代码示例
- Swift BinaryInteger >>=(_:_:)用法及代码示例
- Swift BinaryInteger ~(_:)用法及代码示例
- Swift BinaryInteger |=(_:_:)用法及代码示例
- Swift BinaryInteger <<(_:_:)用法及代码示例
- Swift BinaryInteger >>(_:_:)用法及代码示例
- Swift BinaryInteger init(exactly:)用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 BinaryInteger +(_:_:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。