Guessing the errors, I expect that performOperation() should return a Double? (optional double), and if the fact returns nothing.
those. this is probably the signature:
func performOperation(operation: String) {
.. while in reality it should be:
func performOperation(operation: String) -> Double? {
The reason why I think so is because this line: if let result = brain.performOperation(operation) is a call to "expand optional", and it expects the assigned value to be an optional type. Later, you assign a value that you expand into a variable that appears to be of type Double.
By the way, a shorter (and more readable) way to write the same thing:
displayValue = brain.performOperation(operation) ?? 0.0
source share