Learning to write fast code, considering a multidimensional array, you want to iterate over the array, derive the mathematical function stored in the second column, and then add its first column value to 4 separate arrays (not yet created), so in the end I will have 4 arrays containing number from the first column.
However on the line
Function = array3D[index]
I get an error: fast execution was interrupted due to exc_bad_access
Can anyone help? Code below
var array3D: [[String]] = [["1", "+"], ["3", "-"], ["5", "x"], ["7", "/"]] var arrayAdd = [""] var arrayMinus = [""] var arrayMultiple = [""] var arrayDivide = [""] var count = array3D.count var countIsZero = false if count != 0 { countIsZero = true } if countIsZero { for index in 0...count { var Function = "" Function = array3D[count][1] println(Function) switch Function { case "+": arrayAdd.append(array3D[count][0]) case "-": arrayMinus.append(array3D[count][0]) case "x": arrayMultiple.append(array3D[count][0]) case "/": arrayDivide.append(array3D[count][0]) default: "" } } }
source share