Change in recent Swift update regarding mutating structs? -


i following along in stanford ios course , have question believe related recent update. here section of code:

func evaluate(ops: [op]) -> (result: double?,remainingops: [op]) {     let op = ops.removelast() //*i thought ops immutable?          } 

on video, instructor gets error says cannot because ops immutable. makes complete sense when try typing in not error. mean? change in recent swift update structs passed methods mutable? ideas? in video, instructor solves problem creating instance variable copy of ops no longer error , understand why is.

edit when typing playground still error not in swift file. reference here entire file far. ideas? want understand going on here:

import foundation  class calculatorbrain {      private enum op {         case operand(double)         case unaryoperation(string,double -> double)         case binaryoperation(string, (double,double) -> double)     }      private var opstack = [op]()      private var knownops = [string:op]()      init() {         knownops["×"] = op.binaryoperation("×",*)         knownops["÷"] = op.binaryoperation("÷") { $1 / $0 }         knownops["+"] = op.binaryoperation("+",+)         knownops["−"] = op.binaryoperation("−") { $1 - $0 }         knownops["^"] = op.binaryoperation("^") { pow($1,$0) }         knownops["√"] = op.unaryoperation("√",sqrt)         knownops["sin"] = op.unaryoperation("sin") { sin($0) }         knownops["cos"] = op.unaryoperation("cos") { cos($0) }         knownops["tan"] = op.unaryoperation("tan") { tan($0) }      }      func evaluate(ops: [op]) -> (result: double?,remainingops: [op]) {         if !ops.isempty {             let op = ops.removelast()//*error should appear here not          }         return (nil,ops)     }      func evaluate() -> double? {      }      func pushoperand(operand: double) {         opstack.append(op.operand(operand))     }      func performoperation(symbol: string) {         if let operation = knownops[symbol] {             opstack.append(operation)         }     } } 

i have checked see if implicitly makes copy of array. no not. xcode in bug think. please restart xcode , try again. go utilities bar, move cursor on ops array in code. observe type? "error type" or else? can check pressing opt , click variable.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -