swift初心者です。
今回、swiftで簡単な電卓を作ってみたのですが、AppDelegate.swiftでエラーが起きてしまいアプリが中断されてしまいます。
エラー内容はclass AppDelegate: UIResponder, UIApplicationDelegate の行で以下のようなエラー文でした。
Thread 1: signal SIGABRD
そして、下にはViewController.swiftのソースを載せます。```lang-swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. myButton0.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) myButton1.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) myButton2.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) myButton3.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) myButton4.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) myButton5.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) myButton6.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) myButton7.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) myButton8.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) myButton9.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) myButtonPlus.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) myButtonMinus.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) myButtonMulti.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) myButtonDivision.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) myButtonEqual.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBOutlet weak var myLabel: UILabel!;
// 数字を表すプロパティ
@IBOutlet weak var myButton0: UIButton!;
@IBOutlet weak var myButton1: UIButton!;
@IBOutlet weak var myButton2: UIButton!;
@IBOutlet weak var myButton3: UIButton!;
@IBOutlet weak var myButton4: UIButton!;
@IBOutlet weak var myButton5: UIButton!;
@IBOutlet weak var myButton6: UIButton!;
@IBOutlet weak var myButton7: UIButton!;
@IBOutlet weak var myButton8: UIButton!;
@IBOutlet weak var myButton9: UIButton!;
@IBOutlet weak var myButtonPlus: UIButton!;//足し算のプロパティ @IBOutlet weak var myButtonMinus: UIButton!;//引き算のプロパティ @IBOutlet weak var myButtonMulti: UIButton!;//掛け算のプロパティ @IBOutlet weak var myButtonDivision: UIButton!;//割り算のプロパティ @IBOutlet weak var myButtonEqual: UIButton!; func buttonClicked(sender: UIButton){ switch sender { case myButtonPlus,myButtonMinus,myButtonMulti,myButtonDivision: command = sender.titleLabel!.text!; inputR = true;//右辺の入力に移る case myButtonEqual: //ボタンがタップされた if inputR { var result: Int?; switch command { case "+": result = left.toInt()! + right.toInt()!; case "-": result = left.toInt()! - right.toInt()!; case "*": result = left.toInt()! * right.toInt()!; case "/": result = left.toInt()! / right.toInt()!; default : result = 0; } myLabel.text = "\(result)";//結果の表示 //次の入力のためのデータの初期化 left = ""; right = ""; inputR = false; } default : //ボタン0-9がタップされた時 if inputR { //右辺入力時の動作 right = right + sender.titleLabel!.text!; myLabel.text = right; } else { //左辺入力中なら left = left + sender.titleLabel!.text!; myLabel.text = left; } } } var right: String = "";//計算の右辺となる文字列 var left: String = "";//計算の左辺となる文字列 var inputR: Bool = false;//右辺を入力中かどうか var command: String = "";//計算に使用するコマンド
}