操作符
+(_:
+(_:_:)
将两个值相加并产生它们的总和。
必需的。
声明
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 AdditiveArithmetic +(_:)用法及代码示例
- Swift AdditiveArithmetic -(_:_:)用法及代码示例
- Swift AdditiveArithmetic用法及代码示例
- Swift Array enumerated()用法及代码示例
- Swift AnySequence elementsEqual(_:)用法及代码示例
- Swift ArraySlice starts(with:)用法及代码示例
- Swift ArraySlice reduce(_:_:)用法及代码示例
- Swift Array allSatisfy(_:)用法及代码示例
- Swift AnyCollection min()用法及代码示例
- Swift AsyncThrowingFlatMapSequence min()用法及代码示例
- Swift AnyBidirectionalCollection elementsEqual(_:)用法及代码示例
- Swift AnyRandomAccessCollection randomElement(using:)用法及代码示例
- Swift AsyncPrefixWhileSequence reduce(_:_:)用法及代码示例
- Swift AsyncThrowingMapSequence reduce(_:_:)用法及代码示例
- Swift AnyBidirectionalCollection lexicographicallyPrecedes(_:)用法及代码示例
- Swift AnyHashable ==(_:_:)用法及代码示例
- Swift AsyncDropWhileSequence allSatisfy(_:)用法及代码示例
- Swift AsyncSequence dropFirst(_:)用法及代码示例
- Swift AnyBidirectionalCollection split(separator:maxSplits:omittingEmptySubsequences:)用法及代码示例
- Swift AnyRandomAccessCollection first(where:)用法及代码示例
- Swift AnyBidirectionalCollection sorted()用法及代码示例
- Swift AsyncDropFirstSequence filter(_:)用法及代码示例
- Swift AsyncSequence reduce(_:_:)用法及代码示例
- Swift AsyncFlatMapSequence min()用法及代码示例
- Swift AsyncThrowingPrefixWhileSequence drop(while:)用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 AdditiveArithmetic +(_:_:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。