###前提・実現したいこと
UILabelに入力された数字をDouble型に変換して、簡単な計算をしたいのですが、
計算を行うコードを書くと、Use of unresolved identifier 'num1'というエラーが出てきてしまって困っています。
どなたか助けてください。
###発生している問題・エラーメッセージ
Use of unresolved identifier 'num1' Use of unresolved identifier 'num2'
###該当のソースコード
swift
1import UIKit 2 3class ViewController: UIViewController { 4 5 @IBOutlet weak var siki: UILabel! 6 @IBOutlet weak var resultLabel: UILabel! 7 8 @IBOutlet weak var siki2: UILabel! 9 @IBOutlet weak var sisokuenzan: UILabel! 10 override func viewDidLoad() { 11 super.viewDidLoad() 12 // Do any additional setup after loading the view, typically from a nib. 13 14 } 15 16 override func didReceiveMemoryWarning() { 17 super.didReceiveMemoryWarning() 18 // Dispose of any resources that can be recreated. 19 } 20 21 @IBAction func enzansi(sender: AnyObject) { 22 sisokuenzan.text! = (sender.titleLabel??.text)! 23 } 24 @IBAction func tappedbutton(sender: AnyObject) { 25 if sisokuenzan.text!.characters.count == 0{ 26 siki.text! += (sender.titleLabel??.text)! 27 }else{ 28 siki2.text! += (sender.titleLabel??.text)! 29 } 30 if let text = siki.text{ 31 let numA = NSNumberFormatter() 32 let num1 = numA.numberFromString(text)?.doubleValue 33 } 34 if let text2 = siki2.text{ 35 let numB = NSNumberFormatter() 36 let num2 = numB.numberFromString(text2)?.doubleValue 37 } 38 39 40} 41 42 @IBAction func equal(sender: AnyObject) { 43 44 if sisokuenzan == "+"{ 45 var kekka1 = num1 + num2 46 } 47 48 49} 50}
###試したこと
Double型への
変換コードの位置を変えてみましたがダメでした。
Double型への変換コードの位置を、どう変えてみたのでしょうか?