用法一
操作符
+(_:
+(_:_:)
通過連接序列和集合的元素來創建一個新集合。
聲明
static func + <Other>(lhs: Other, rhs: Self) -> Self where Other : Sequence, Self.Element == Other.Element
參數
lhs
集合或有限序列。
rhs
range-replaceable 集合。
詳述
這兩個參數必須具有相同的Element
類型。例如,您可以連接 Range<Int>
實例的元素和整數數組。
let numbers = [7, 8, 9, 10]
let moreNumbers = (1...6) + numbers
print(moreNumbers)
// Prints "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"
生成的集合在右側具有參數類型。在上麵的示例中,moreNumbers
與 numbers
具有相同的類型,即 [Int]
。
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
用法二
操作符
+(_:
+(_:_:)
通過連接集合和序列的元素來創建新集合。
聲明
static func + <Other>(lhs: Self, rhs: Other) -> Self where Other : Sequence, Self.Element == Other.Element
參數
lhs
range-replaceable 集合。
rhs
集合或有限序列。
詳述
這兩個參數必須具有相同的Element
類型。例如,您可以連接整數數組和Range<Int>
實例的元素。
let numbers = [1, 2, 3, 4]
let moreNumbers = numbers + (5...10)
print(moreNumbers)
// Prints "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"
結果集合具有左側參數的類型。在上麵的示例中,moreNumbers
與 numbers
具有相同的類型,即 [Int]
。
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
用法三
操作符
+(_:
+(_:_:)
通過連接兩個集合的元素來創建一個新集合。
聲明
static func + <Other>(lhs: Self, rhs: Other) -> Self where Other : RangeReplaceableCollection, Self.Element == Other.Element
參數
lhs
range-replaceable 集合。
rhs
另一個range-replaceable 集合。
詳述
這兩個參數必須具有相同的Element
類型。例如,您可以連接兩個整數數組的元素。
let lowerNumbers = [1, 2, 3, 4]
let higherNumbers: ContiguousArray = [5, 6, 7, 8, 9, 10]
let allNumbers = lowerNumbers + higherNumbers
print(allNumbers)
// Prints "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"
結果集合具有左側參數的類型。在上麵的示例中,moreNumbers
與 numbers
具有相同的類型,即 [Int]
。
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相關用法
- Swift String.UnicodeScalarView +=(_:_:)用法及代碼示例
- Swift String.UnicodeScalarView flatMap(_:)用法及代碼示例
- Swift String.UnicodeScalarView min(by:)用法及代碼示例
- Swift String.UnicodeScalarView lastIndex(of:)用法及代碼示例
- Swift String.UnicodeScalarView filter(_:)用法及代碼示例
- Swift String.UnicodeScalarView replaceSubrange(_:with:)用法及代碼示例
- Swift String.UnicodeScalarView compactMap(_:)用法及代碼示例
- Swift String.UnicodeScalarView sorted()用法及代碼示例
- Swift String.UnicodeScalarView split(separator:maxSplits:omittingEmptySubsequences:)用法及代碼示例
- Swift String.UnicodeScalarView shuffled(using:)用法及代碼示例
- Swift String.UnicodeScalarView removeFirst(_:)用法及代碼示例
- Swift String.UnicodeScalarView starts(with:)用法及代碼示例
- Swift String.UnicodeScalarView elementsEqual(_:)用法及代碼示例
- Swift String.UnicodeScalarView remove(at:)用法及代碼示例
- Swift String.UnicodeScalarView lexicographicallyPrecedes(_:)用法及代碼示例
- Swift String.UnicodeScalarView append(_:)用法及代碼示例
- Swift String.UnicodeScalarView contains(_:)用法及代碼示例
- Swift String.UnicodeScalarView enumerated()用法及代碼示例
- Swift String.UnicodeScalarView insert(_:at:)用法及代碼示例
- Swift String.UnicodeScalarView last用法及代碼示例
- Swift String.UnicodeScalarView reversed()用法及代碼示例
- Swift String.UnicodeScalarView shuffled()用法及代碼示例
- Swift String.UnicodeScalarView lastIndex(where:)用法及代碼示例
- Swift String.UnicodeScalarView randomElement()用法及代碼示例
- Swift String.UnicodeScalarView index(_:offsetBy:)用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 String.UnicodeScalarView +(_:_:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。