用法一
实例方法
remove
removeSubrange(_:)
从集合中移除指定子范围内的元素。
声明
mutating func removeSubrange<R>(_ bounds: R) where R : RangeExpression, Self.Index == R.Bound
参数
bounds
要删除的集合的范围。范围的边界必须是集合的有效索引。
详述
移动指定位置之后的所有元素以缩小间隙。此示例从测量数组的中间删除三个元素。
var measurements = [1.2, 1.5, 2.9, 1.2, 1.5]
measurements.removeSubrange(1..<4)
print(measurements)
// Prints "[1.2, 1.5]"
调用此方法可能会使用于此集合的任何现有索引无效。
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
用法二
实例方法
remove
removeSubrange(_:)
从集合中移除指定子范围内的元素。
声明
mutating func removeSubrange(_ bounds: Range<Self.Index>)
参数
bounds
要删除的集合的范围。范围的边界必须是集合的有效索引。
详述
移动指定位置之后的所有元素以缩小间隙。此示例从测量数组的中间删除三个元素。
var measurements = [1.2, 1.5, 2.9, 1.2, 1.5]
measurements.removeSubrange(1..<4)
print(measurements)
// Prints "[1.2, 1.5]"
调用此方法可能会使用于此集合的任何现有索引无效。
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相关用法
- Swift ArraySlice removeAll(where:)用法及代码示例
- Swift ArraySlice remove(at:)用法及代码示例
- Swift ArraySlice removeFirst()用法及代码示例
- Swift ArraySlice removeFirst(_:)用法及代码示例
- Swift ArraySlice reduce(_:_:)用法及代码示例
- Swift ArraySlice reversed()用法及代码示例
- Swift ArraySlice reserveCapacity(_:)用法及代码示例
- Swift ArraySlice replaceSubrange(_:with:)用法及代码示例
- Swift ArraySlice reverse()用法及代码示例
- Swift ArraySlice reduce(into:_:)用法及代码示例
- Swift ArraySlice randomElement()用法及代码示例
- Swift ArraySlice randomElement(using:)用法及代码示例
- Swift ArraySlice starts(with:)用法及代码示例
- Swift ArraySlice prefix(through:)用法及代码示例
- Swift ArraySlice prefix(upTo:)用法及代码示例
- Swift ArraySlice map(_:)用法及代码示例
- Swift ArraySlice append(contentsOf:)用法及代码示例
- Swift ArraySlice shuffled()用法及代码示例
- Swift ArraySlice suffix(from:)用法及代码示例
- Swift ArraySlice lastIndex(of:)用法及代码示例
- Swift ArraySlice prefix(_:)用法及代码示例
- Swift ArraySlice joined()用法及代码示例
- Swift ArraySlice insert(contentsOf:at:)用法及代码示例
- Swift ArraySlice sorted(by:)用法及代码示例
- Swift ArraySlice init(arrayLiteral:)用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 ArraySlice removeSubrange(_:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。