初始化器
init(base:
init(base:bounds:)
在給定集合中創建一個視圖,允許訪問指定範圍內的元素。
聲明
init(
base: Base,
bounds: Range<Base.Index>
)
參數
base
要在其中創建視圖的集合。
bounds
允許在新切片中訪問的索引範圍。
詳述
需要直接調用此方法是不尋常的。相反,通過使用集合的基於範圍的下標或使用返回子序列的方法來創建集合的切片。
let singleDigits = 0...9
let subSequence = singleDigits.dropFirst(5)
print(Array(subSequence))
// Prints "[5, 6, 7, 8, 9]"
在此示例中,表達式 singleDigits.dropFirst(5))
等效於使用 singleDigits
和覆蓋 singleDigits.indices
的最後五個項目的範圍調用此初始化程序。
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相關用法
- Swift Slice init(repeating:count:)用法及代碼示例
- Swift Slice insert(_:at:)用法及代碼示例
- Swift Slice insert(contentsOf:at:)用法及代碼示例
- Swift Slice indices用法及代碼示例
- Swift Slice index(_:offsetBy:limitedBy:)用法及代碼示例
- Swift Slice index(_:offsetBy:)用法及代碼示例
- Swift Slice isEmpty用法及代碼示例
- Swift Slice endIndex用法及代碼示例
- Swift Slice reduce(into:_:)用法及代碼示例
- Swift Slice contains(_:)用法及代碼示例
- Swift Slice removeAll(where:)用法及代碼示例
- Swift Slice +(_:_:)用法及代碼示例
- Swift Slice lastIndex(where:)用法及代碼示例
- Swift Slice removeFirst()用法及代碼示例
- Swift Slice suffix(_:)用法及代碼示例
- Swift Slice starts(with:)用法及代碼示例
- Swift Slice reduce(_:_:)用法及代碼示例
- Swift Slice sorted()用法及代碼示例
- Swift Slice split(separator:maxSplits:omittingEmptySubsequences:)用法及代碼示例
- Swift Slice dropLast(_:)用法及代碼示例
- Swift Slice sorted(by:)用法及代碼示例
- Swift Slice partition(by:)用法及代碼示例
- Swift Slice last(where:)用法及代碼示例
- Swift Slice joined(separator:)用法及代碼示例
- Swift Slice base用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Slice init(base:bounds:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。