Initializer for conditional binding must have Optional type, not"()"

I couldn't solve an "if let" issue in my code. Based on the error it says that I must use an optional type?

@IBAction func operate(sender: UIButton) {

    if userIsInTheMiddleOfTypingANumber{
        enter()
    }
    if let operation = sender.currentTitle {
        if let result = calcModel.performOperation(operation){
            displayValue = result
        }else {
            displayValue = 0
        }
    }
}

Answers


I suspect that your problem is in this line:

if let result = calcModel.performOperation(operation)

Your performOperation function's return type is (), or void, which means it doesn't return anything. Chances are, to get the error in the title, your performOperation function on calcModel has the following signature:

func performOperation(operation: String) {

Note the lack of an arrow and type. If you're going to return a result, the signature should be something like this:

func performOperation(operation: String) -> Int {

You would only need the if let, if you decided to return Int?.


Need Your Help

Update home link in wordpress

linux wordpress

I am using the frontier theme.

Firing many requests at a node app for test causing socket hang up / ECONNRESET error

node.js express brute-force supertest

I'm trying to write a test for my application, where by I've used express-brute to prevent brute force attacks.