swift初心者です。
このたび、swiftを使って簡単な電卓を作ってみたのですが、AppDelegate.swiftの
class AppDelegate: UIResponder, UIApplicationDelegate
の行で以下のようなエラー文が発生していました。
Thread 1:signal SIGABRT
原因は何でしょうか?
下にviewController.swiftのソースコードを載せておきます
lang
1import UIKit 2 3class ViewController: UIViewController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 // Do any additional setup after loading the view, typically from a nib. 8 myButton0.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) 9 myButton1.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) 10 myButton2.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) 11 myButton3.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) 12 myButton4.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) 13 myButton5.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) 14 myButton6.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) 15 myButton7.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) 16 myButton8.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) 17 myButton9.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) 18 19 myButtonPlus.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) 20 myButtonMinus.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) 21 myButtonMulti.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) 22 myButtonDivision.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) 23 myButtonEqual.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside) 24 } 25 26 override func didReceiveMemoryWarning() { 27 super.didReceiveMemoryWarning() 28 // Dispose of any resources that can be recreated. 29 } 30 31 @IBOutlet weak var myLabel: UILabel!; 32 33// 数字を表すプロパティ 34 @IBOutlet weak var myButton0: UIButton!; 35 @IBOutlet weak var myButton1: UIButton!; 36 @IBOutlet weak var myButton2: UIButton!; 37 @IBOutlet weak var myButton3: UIButton!; 38 @IBOutlet weak var myButton4: UIButton!; 39 @IBOutlet weak var myButton5: UIButton!; 40 @IBOutlet weak var myButton6: UIButton!; 41 @IBOutlet weak var myButton7: UIButton!; 42 @IBOutlet weak var myButton8: UIButton!; 43 @IBOutlet weak var myButton9: UIButton!; 44 45 @IBOutlet weak var myButtonPlus: UIButton!;//足し算のプロパティ 46 @IBOutlet weak var myButtonMinus: UIButton!;//引き算のプロパティ 47 @IBOutlet weak var myButtonMulti: UIButton!;//掛け算のプロパティ 48 @IBOutlet weak var myButtonDivision: UIButton!;//割り算のプロパティ 49 50 @IBOutlet weak var myButtonEqual: UIButton!; 51 52 func buttonClicked(sender: UIButton){ 53 switch sender { 54 case myButtonPlus,myButtonMinus,myButtonMulti,myButtonDivision: 55 command = sender.titleLabel!.text!; 56 inputR = true;//右辺の入力に移る 57 58 case myButtonEqual: 59 //ボタンがタップされた 60 if inputR { 61 var result: Int?; 62 63 switch command { 64 case "+": 65 result = left.toInt()! + right.toInt()!; 66 case "-": 67 result = left.toInt()! - right.toInt()!; 68 case "*": 69 result = left.toInt()! * right.toInt()!; 70 case "/": 71 result = left.toInt()! / right.toInt()!; 72 73 default : 74 result = 0; 75 } 76 myLabel.text = "\(result)";//結果の表示 77 //次の入力のためのデータの初期化 78 left = ""; 79 right = ""; 80 inputR = false; 81 } 82 83 default : 84 //ボタン0-9がタップされた時 85 if inputR { 86 //右辺入力時の動作 87 right = right + sender.titleLabel!.text!; 88 myLabel.text = right; 89 } else { 90 //左辺入力中なら 91 left = left + sender.titleLabel!.text!; 92 myLabel.text = left; 93 94 } 95 96 } 97 98 } 99 100 var right: String = "";//計算の右辺となる文字列 101 var left: String = "";//計算の左辺となる文字列 102 var inputR: Bool = false;//右辺を入力中かどうか 103 var command: String = "";//計算に使用するコマンド 104 105 106} 107
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/03/19 09:56