ios - Immutable array on a var? -


i getting error:

immutable value of type 'array character>' has mutating members of name removeatindex()

the array should have contents because removeatindex line in loop who's condition if count > 1

func evaluatepostfix(expression:array<character>) -> character {     var stack:array<character> = []     var count = -1 // start @ -1 make 0 indexing      if expression.count == 0 {         return "x"     }      while expression.count > 1 {         if expression.count == 1 {             let answer = expression[0]             return answer         }          var expressiontokenasstring:string = string(expression[0])         if let number = expressiontokenasstring.toint() {             stack.append(expression[0])             expression.removeatindex(0)             count++         } else { // capture token, remove lefthand , righthand, solve, push result             var token = expression(count + 1)             var righthand = stack(count)             var lefthand = stack(count - 1)             stack.removeatindex(count)             stack.removeatindex(count - 1)             stack.append(evaluatesubexpression(lefthand, righthand, token))         }     } } 

anyone have idea why is? thanks!

because function parameters implicitly passed value "let", , hence constant within function, no matter outside function.

to modify value within function (which won't affect value on return), can explicitly use var:

func evaluatepostfix(var expression:array<character>) -> character { ... } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -