swift2の整数型変数の中身を調べる方法で詰まった。。
この電卓アプリをswift2で書き直しをしているんですが、
https://www.youtube.com/watch?v=DGt1yBxBw9k&index=5&list=WL
class ViewController: UIViewController {
var lastNumber: String = ""
@IBOutlet var answerField: UILabel!
@IBOutlet var operatorLabel: UILabel?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func buttonTapped(theButton: UIButton) {
if answerField.text == "0" {
answerField.text = theButton.titleLabel!.text!
print(answerField!.text!)
} else {
answerField.text = (answerField.text)! + theButton.titleLabel!.text!
print(answerField.text!)
}
}
@IBAction func plusTapped(theButton: UIButton) {
print("plus tapped")
if operatorLabel?.text == "" {
operatorLabel!.text = "+"
answerField!.text = "0"
} else {
operatorLabel!.text = "+"
}
}
@IBAction func minusTapped(theButton: UIButton) {
print("minus tapped")
if operatorLabel?.text == "" {
operatorLabel!.text = "-"
lastNumber = answerField.text!
answerField!.text = "0"
} else {
operatorLabel!.text = "- "
}
}
@IBAction func clearTapped(theButton: UIButton) {
answerField.text = "0"
operatorLabel!.text = ""
lastNumber = ""
print("clearButton Tapped")
}
@IBAction func enterTapped(_: AnyObject) {
var num1: Int = Int(lastNumber)!
var num2: Int = Int(answerField.text!)!
if !num1 || !num2 {
showError()
return
}
func showError() {
print("Error")
}
}
if !num1 || !num2 {
showError()
return
}
この部分でエラーが出ます。
swift2ではどのように書き換えるんでしょうか?
変数に中身があるか確認をするということはわかっているんですが。お願いします。