on-internet
← Community

How do I have calculations done when everything is in a string?

Stack Overflow ·

On this calculator project, when a number button is pressed I have it saved in an array: @IBAction func buttonPressed(_ sender: UIButton) { if numBtnPressed == true { numArray.append(sender.title(for: .normal)!) } } If the button labeled 1 is pressed it stores ["1"] as a string in the empty array numArray. I have a separate structure for operators: struct calcFuncs { var add : String var subtract : String var divide : String var multiply : String } var calc = calcFuncs(add: "+", subtract: "-", divide: "/", multiply: "x") How do I, with a string of numbers and operators (1 + 2 x 3 + 4 / 5 + 5),

Comments

Sign in or sign up to comment and upvote.

No comments yet.