预期的声明错误

时间:2016-01-19 12:58:12

标签: ios swift declaration object-expected

我的问题是我尝试制作一个计算器,但由于预期的声明问题,我没有这样做。我检查了有关预期声明的其他问题,但我没有解决这个问题。

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var Screen: UILabel!
    var firstNumber = Int()
    var secondNumber = Int()
    var isTypingNumber = false
    var result = Int()
    var operation = ""


    @IBAction func number(sender: AnyObject) {
        let number = sender.currentTitle
        if isTypingNumber == true {
            Screen.text =   Screen.text! + number!!
        } else {
            Screen.text = number;
        }
        isTypingNumber = true


    }


    @IBAction func operation(sender: AnyObject) {
        isTypingNumber = false
        firstNumber = Int(Screen.text!)!
        operation = sender.currentTitle!!

    }

    @IBAction func equals(sender: AnyObject) {
        secondNumber = Int(Screen.text!)!
        if operation == "+" {
            result = firstNumber + secondNumber
        } else if operation == "-" {
            result = firstNumber - secondNumber
        } else if operation == "x" {
            result = firstNumber * secondNumber

        }else {
            result = firstNumber / secondNumber

        }
        Screen.text = "\(result)"

        func clear(sender: AnyObject) {
            firstNumber = 0
            secondNumber = 0
            isTypingNumber = false
            result = 0
            Screen.text = "\(result)"

        }





        func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
        }

        func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }

}

1 个答案:

答案 0 :(得分:1)

您在equals函数中缺少右括号:

@IBAction func equals(sender: AnyObject) {
    secondNumber = Int(Screen.text!)!
    if operation == "+" {
        result = firstNumber + secondNumber
    } else if operation == "-" {
        result = firstNumber - secondNumber
    } else if operation == "x" {
        result = firstNumber * secondNumber

    }else {
        result = firstNumber / secondNumber

    }
    Screen.text = "\(result)"
} // missing this