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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -