ios - Swift array set value of index not working -


i have method (contents below) queue2 [int]. printed lot of things see if working point.

public func cool(item: int) {     println(item)     println(back)     //queue2.insert(item, atindex: back)     queue2[back] = item     println(queue2.description)     println("done") } 

the problem fails @ runtime , don't know why. apple docs can set value of index in array notation, doesn't work. if uncomment commented line , comment out 1 below it, runs fine doesn't provide functionality need. gives?

if queue2 empty, line illegal no matter what back is:

queue2[back] = item 

you cannot refer index doesn't exist, , empty array has no indexes (indices).


Comments