操作符
..<(_:)
返回不包括上限的部分范围。
声明
static func ..< (maximum: Self) -> PartialRangeUpTo<Self>
参数
maximum
范围的上限。
详述
使用前缀半开范围运算符(前缀 ..<
)创建符合 Comparable
协议的任何类型的部分范围。此示例创建一个 PartialRangeUpTo<Double>
实例,其中包含小于 5.0
的任何值。
let upToFive = ..<5.0
upToFive.contains(3.14) // true
upToFive.contains(6.28) // false
upToFive.contains(5.0) // false
您可以使用集合索引的这种类型的部分范围来表示从集合开始到但不包括部分范围上限的范围。
let numbers = [10, 20, 30, 40, 50, 60, 70]
print(numbers[..<3])
// Prints "[10, 20, 30]"
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相关用法
- Swift UInt16 ..<(_:_:)用法及代码示例
- Swift UInt16 ...(_:)用法及代码示例
- Swift UInt16 ...(_:_:)用法及代码示例
- Swift UInt16 &*=(_:_:)用法及代码示例
- Swift UInt16 leadingZeroBitCount用法及代码示例
- Swift UInt16 %=(_:_:)用法及代码示例
- Swift UInt16 &<<(_:_:)用法及代码示例
- Swift UInt16 -(_:_:)用法及代码示例
- Swift UInt16 <<=(_:_:)用法及代码示例
- Swift UInt16 &-(_:_:)用法及代码示例
- Swift UInt16 random(in:)用法及代码示例
- Swift UInt16 init(_:)用法及代码示例
- Swift UInt16 quotientAndRemainder(dividingBy:)用法及代码示例
- Swift UInt16 init(clamping:)用法及代码示例
- Swift UInt16 /(_:_:)用法及代码示例
- Swift UInt16 init(integerLiteral:)用法及代码示例
- Swift UInt16 *(_:_:)用法及代码示例
- Swift UInt16 &+(_:_:)用法及代码示例
- Swift UInt16 ^(_:_:)用法及代码示例
- Swift UInt16 ^=(_:_:)用法及代码示例
- Swift UInt16 &<<=(_:_:)用法及代码示例
- Swift UInt16 %(_:_:)用法及代码示例
- Swift UInt16 &>>(_:_:)用法及代码示例
- Swift UInt16 <<(_:_:)用法及代码示例
- Swift UInt16 +=(_:_:)用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 UInt16 ..<(_:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。