Swift Array has a first function that returns the first element of the array (or nil if the array is empty.)
Array
first
Is there a built-in function that will return the rest of the array without the first element?
There is one that will help you get what you are looking for:
func dropFirst<Seq : Sliceable>(s: Seq) -> Seq.SubSlice
Use this:
let a = [1, 2, 3, 4, 5, 6, 7, 18, 9, 10] let b = dropFirst(a) // [2, 3, 4, 5, 6, 7, 18, 9, 10]
The correct answer for Swift 2.2, 3+ :
let restOfArray = Array(array.dropFirst())
Update for Swift 3+ :
like @leanne mentioned in the comments below, it looks like this is now possible:
let restOfArray = array.dropFirst()
Not.
extension Array { func skip(count:Int)->[T] {return [T](self[count..<self.count])} }
https://github.com/mythz/swift-linq-examples/blob/master/src/LinqExamples/extensions.swift