How do I access the not-the-first elements of an array in Swift?

Robert Atkins picture Robert Atkins · Nov 18, 2014 · Viewed 7.2k times · Source

Swift's Array has a first function which returns the first element of the array (or nil if the array is empty.)

Is there a built-in function that will return the remainder of the array without the first element?

Answer

MirekE picture MirekE · Nov 19, 2014

There is one that might help you get what you are looking for:

func dropFirst<Seq : Sliceable>(s: Seq) -> Seq.SubSlice

Use like 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]