用法一
操作符
...(_:)
返回不超過(包括)其上限的部分範圍。
聲明
static func ... (maximum: Self) -> PartialRangeThrough<Self>
參數
maximum
範圍的上限。
詳述
使用前綴封閉範圍運算符(前綴 ...
)創建符合 Comparable
協議的任何類型的部分範圍。此示例創建一個 PartialRangeThrough<Double>
實例,其中包含任何小於或等於 5.0
的值。
let throughFive = ...5.0
throughFive.contains(4.0) // true
throughFive.contains(5.0) // true
throughFive.contains(6.0) // false
您可以使用集合索引的這種類型的部分範圍來表示從集合開始到(包括)部分範圍的上限的範圍。
let numbers = [10, 20, 30, 40, 50, 60, 70]
print(numbers[...3])
// Prints "[10, 20, 30, 40]"
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
用法二
操作符
...(_:)
返回從下限向上延伸的部分範圍。
聲明
static func ... (minimum: Self) -> PartialRangeFrom<Self>
參數
minimum
範圍的下限。
詳述
使用後綴範圍運算符 (postfix ...
) 創建符合 Comparable
協議的任何類型的部分範圍。此示例創建一個 PartialRangeFrom<Double>
實例,其中包含任何大於或等於 5.0
的值。
let atLeastFive = 5.0...
atLeastFive.contains(4.0) // false
atLeastFive.contains(5.0) // true
atLeastFive.contains(6.0) // true
您可以使用集合索引的這種類型的部分範圍來表示從部分範圍的下限到集合末尾的範圍。
let numbers = [10, 20, 30, 40, 50, 60, 70]
print(numbers[3...])
// Prints "[40, 50, 60, 70]"
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相關用法
- Swift UInt64 ...(_:_:)用法及代碼示例
- Swift UInt64 ..<(_:_:)用法及代碼示例
- Swift UInt64 ..<(_:)用法及代碼示例
- Swift UInt64 *(_:_:)用法及代碼示例
- Swift UInt64 random(in:using:)用法及代碼示例
- Swift UInt64 /(_:_:)用法及代碼示例
- Swift UInt64 ^=(_:_:)用法及代碼示例
- Swift UInt64 ^(_:_:)用法及代碼示例
- Swift UInt64 &<<=(_:_:)用法及代碼示例
- Swift UInt64 init(_:radix:)用法及代碼示例
- Swift UInt64 &-(_:_:)用法及代碼示例
- Swift UInt64 &>>(_:_:)用法及代碼示例
- Swift UInt64 &(_:_:)用法及代碼示例
- Swift UInt64 /=(_:_:)用法及代碼示例
- Swift UInt64 ==(_:_:)用法及代碼示例
- Swift UInt64 >>=(_:_:)用法及代碼示例
- Swift UInt64 random(in:)用法及代碼示例
- Swift UInt64 &>>=(_:_:)用法及代碼示例
- Swift UInt64 &=(_:_:)用法及代碼示例
- Swift UInt64 trailingZeroBitCount用法及代碼示例
- Swift UInt64 &+=(_:_:)用法及代碼示例
- Swift UInt64 >>(_:_:)用法及代碼示例
- Swift UInt64 multipliedFullWidth(by:)用法及代碼示例
- Swift UInt64 leadingZeroBitCount用法及代碼示例
- Swift UInt64 &*=(_:_:)用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 UInt64 ...(_:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。