错误 - EXC_BREAKPOINT(代码=1,子代码=0x100308448)
Posted
技术标签:
【中文标题】错误 - EXC_BREAKPOINT(代码=1,子代码=0x100308448)【英文标题】:Error - EXC_BREAKPOINT (code=1, subcode=0x100308448) 【发布时间】:2017-07-31 10:14:27 【问题描述】:error - EXC_BREAKPOINT (code=1, subcode=0x100308448)
每次我尝试双击分割按钮时,Xcode 都会发出 EXC_BREAKPOINT(代码 = 1,子代码 = 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
【问题讨论】:
当您可以将错误消息复制粘贴到引用块中时,请不要使用图像。另外,缩进你的代码。 除法运算发生代码崩溃时的第一个想法应该是:确保你永远不会被零除。 【参考方案1】:可惜$0
只能是Int
,而不是Double
。
您应该像下面这样详细描述内联函数。
operateWithTwoOperands first, second in return first / second;
感谢您的阅读。
【讨论】:
以上是关于错误 - EXC_BREAKPOINT(代码=1,子代码=0x100308448)的主要内容,如果未能解决你的问题,请参考以下文章
prepareForSegue 错误线程 1: EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
Xcode: 如何修复线程 5: EXC_BREAKPOINT (code=1, subcode=0x10025c76c)
线程 1: EXC_BREAKPOINT (code=1, subcode=0x10136bb50) - swift
将视图控制器分配给 prepareForSegue 中的变量时的 Swift EXC_BREAKPOINT
Swift PrepareForSegue EXC_BREAKPOINT
println 中的错误... EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0) swift