error - EXC_BREAKPOINT (code=1, subcode=0x100308448)
每次我试图双击divide按钮时,Xcode都会发出EXC_断点(code=1,subcode=0x100308448),我的应用程序就会崩溃。你能帮我解决这个问题吗?
Dividing button - EXC_BREAKPOINT(...)

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var displayResultLabel: UILabel!
    var stillTyping = false
    var dotIsPlaced = false
    var firstOperand: Double = 0
    var secondOperand: Double = 0
    var operationSign: String = ""


    var currentInput: Double {
        get {
            return Double (displayResultLabel.text!)!
        }
        set {
            let value = "\(newValue)"
            let ValueArray = (value.components(separatedBy:"."))
            if ValueArray[1] == "0" {
                displayResultLabel.text = "\(ValueArray[0])"
            } else {
                displayResultLabel.text = "\(newValue)"
            }
            stillTyping = false
        }
    }

    @IBAction func numberPressed(_ sender: UIButton) {
        let number = sender.currentTitle!

        if stillTyping {
            if (displayResultLabel.text?.characters.count)! < 20 {
                displayResultLabel.text = displayResultLabel.text! + number
            }
        } else {
            displayResultLabel.text = number
            stillTyping = true
        }
    }

    @IBAction func twoOperandsSignPressed(sender: UIButton) {
        operationSign = sender.currentTitle!
        firstOperand = currentInput
        stillTyping = false
        dotIsPlaced = false
    }

    func operateWithTwoOperands(operation: (Double, Double) -> Double) {
        currentInput = operation(firstOperand, secondOperand)
        stillTyping = false
    }

    @IBAction func equalitySignPressed(sender: UIButton) {

        if stillTyping {
            secondOperand = currentInput
        }

        dotIsPlaced = false

        switch operationSign {

        case "+":
            operateWithTwoOperands{$0 + $1}

        case "-":
            operateWithTwoOperands{$0 - $1}

        case "✕":
            operateWithTwoOperands{$0 * $1}

        case "÷":
            operateWithTwoOperands{$0 / $1}
        default: break

        }
    }

    @IBAction func clearButtonPressed(_ sender: UIButton) {
        firstOperand = 0
        secondOperand = 0
        currentInput = 0
        displayResultLabel.text = "0"
        dotIsPlaced = false
        operationSign = ""

    }

    // +,-
    @IBAction func plusMinusButtonPressed(_ sender: UIButton) {
        currentInput = -currentInput
    }

    @IBAction func percentageButtonPressed(_ sender: UIButton) {
        if firstOperand == 0 {
            currentInput = currentInput / 100
        } else {
            secondOperand = firstOperand * currentInput / 100
        }
    }

    @IBAction func squareRootButtonPressed(_ sender: UIButton) {
        currentInput = sqrt(currentInput)
    }

    @IBAction func dotButtonPressed(_ sender: UIButton) {
        if stillTyping && !dotIsPlaced {
            displayResultLabel.text = displayResultLabel.text! + "."
            dotIsPlaced = true
        } else if !stillTyping && !dotIsPlaced {
            displayResultLabel.text = "0."
        }

    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
    }

}

最佳答案

可惜$0只能Int,不能Double
您应该像下面这样详细描述内嵌函数。

operateWithTwoOperands {first, second in return first / second;}

谢谢你的阅读。

关于ios - 错误-EXC_BREAKPOINT(代码= 1,子代码= 0x100308448),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45413088/

10-10 10:34