实例方法
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 BidirectionalCollection subscript(_:)用法及代码示例
- Swift BidirectionalCollection last(where:)用法及代码示例
- Swift BidirectionalCollection lastIndex(where:)用法及代码示例
- Swift BidirectionalCollection lastIndex(of:)用法及代码示例
- Swift BidirectionalCollection indices用法及代码示例
- Swift BidirectionalCollection index(_:offsetBy:)用法及代码示例
- Swift BidirectionalCollection reversed()用法及代码示例
- Swift BidirectionalCollection joined(separator:)用法及代码示例
- Swift BidirectionalCollection index(_:offsetBy:limitedBy:)用法及代码示例
- Swift BidirectionalCollection suffix(_:)用法及代码示例
- Swift BidirectionalCollection last用法及代码示例
- Swift BinaryInteger quotientAndRemainder(dividingBy:)用法及代码示例
- Swift BinaryInteger trailingZeroBitCount用法及代码示例
- Swift BinaryInteger init(clamping:)用法及代码示例
- Swift BinaryInteger <<=(_:_:)用法及代码示例
- Swift BinaryInteger !=(_:_:)用法及代码示例
- Swift BinaryInteger /(_:_:)用法及代码示例
- Swift BinaryInteger init(truncatingIfNeeded:)用法及代码示例
- Swift BinaryInteger ==(_:_:)用法及代码示例
- Swift BinaryFloatingPoint binade用法及代码示例
- Swift BinaryInteger init(_:)用法及代码示例
- Swift BinaryInteger %=(_:_:)用法及代码示例
- Swift BinaryFloatingPoint random(in:using:)用法及代码示例
- Swift BinaryInteger &=(_:_:)用法及代码示例
- Swift BinaryInteger |(_:_:)用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 BidirectionalCollection dropLast(_:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。