实例方法
drop
dropLast(_:)
返回一个包含除指定数量的最终元素之外的所有元素的子序列。
声明
func dropLast(_ k: Int) -> Self.SubSequence
返回值
一个从末尾去掉k
元素的子序列。
参数
k
要从集合末尾丢弃的元素数。
k
必须大于或等于零。
详述
如果要删除的元素数超过集合中的元素数,则结果为空子序列。
let numbers = [1, 2, 3, 4, 5]
print(numbers.dropLast(2))
// Prints "[1, 2, 3]"
print(numbers.dropLast(10))
// Prints "[]"
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相关用法
- Swift ContiguousArray dropFirst(_:)用法及代码示例
- Swift ContiguousArray forEach(_:)用法及代码示例
- Swift ContiguousArray insert(contentsOf:at:)用法及代码示例
- Swift ContiguousArray reserveCapacity(_:)用法及代码示例
- Swift ContiguousArray lexicographicallyPrecedes(_:)用法及代码示例
- Swift ContiguousArray elementsEqual(_:)用法及代码示例
- Swift ContiguousArray isEmpty用法及代码示例
- Swift ContiguousArray suffix(from:)用法及代码示例
- Swift ContiguousArray endIndex用法及代码示例
- Swift ContiguousArray reduce(_:_:)用法及代码示例
- Swift ContiguousArray split(separator:maxSplits:omittingEmptySubsequences:)用法及代码示例
- Swift ContiguousArray sort()用法及代码示例
- Swift ContiguousArray firstIndex(of:)用法及代码示例
- Swift ContiguousArray replaceSubrange(_:with:)用法及代码示例
- Swift ContiguousArray contains(_:)用法及代码示例
- Swift ContiguousArray first(where:)用法及代码示例
- Swift ContiguousArray append(contentsOf:)用法及代码示例
- Swift ContiguousArray randomElement(using:)用法及代码示例
- Swift ContiguousArray prefix(upTo:)用法及代码示例
- Swift ContiguousArray withUnsafeBufferPointer(_:)用法及代码示例
- Swift ContiguousArray index(_:offsetBy:limitedBy:)用法及代码示例
- Swift ContiguousArray joined(separator:)用法及代码示例
- Swift ContiguousArray prefix(through:)用法及代码示例
- Swift ContiguousArray subscript(_:)用法及代码示例
- Swift ContiguousArray max()用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 ContiguousArray dropLast(_:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。