swift2 - How do you use Swift 2.0 popFirst() on an Array? -


swift 2.0 poplast() works on array, this:

var arr = [1,2,3] let = arr.poplast() 

now arr [1,2] , i 3 (wrapped in optional).

but although there popfirst(), doesn't compile. i'm pretty sure used to, doesn't now:

var arr = [1,2,3] let = arr.popfirst() // compile error 

what's going on here? when method usable?

oddly, popfirst works on array derivatives such slices. so, example, compiles:

let arr = [1,2,3] var arrslice = arr[arr.indices] let = arrslice.popfirst() 

now arrslice [2,3] (as slice), i 1 (wrapped in optional), , arr untouched.

so that's how use it.

but not understand why odd restriction imposed on use of popfirst(). see how imposed (in swift header) don't see why.

edit thinking more, i'm guessing has efficiency. when call popfirst() on slice, amounts sparse array: there no index 0. didn't have slide elements down 1 slot; instead, incremented startindex.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -