Skip to content

Instantly share code, notes, and snippets.

@masakid
Last active August 29, 2015 14:16
Show Gist options
  • Save masakid/1fb45a4c5a70ddb0931a to your computer and use it in GitHub Desktop.
Save masakid/1fb45a4c5a70ddb0931a to your computer and use it in GitHub Desktop.
lesson3
//
// ViewController.swift
// Problem_part3
//
// Created by masakid on 2015/03/08.
// Copyright (c) 2015年 masaki.k. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var calcStr1: UILabel!
@IBOutlet weak var calcStr2: UILabel!
@IBOutlet weak var resultLabel: UILabel!
@IBOutlet weak var textField1: UITextField!
@IBOutlet weak var textField2: UITextField!
@IBOutlet weak var switch1: UISwitch!
@IBOutlet weak var switch2: UISwitch!
override func viewDidLoad() {
super.viewDidLoad()
self.switch1.on = false
self.switch2.on = false
self.calcStr1.text = ""
self.calcStr2.text = ""
self.resultLabel.text = ""
// 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 pressButton(sender: AnyObject) {
//入力値取得
let num1 = self.textField1.text.toInt() ?? 0
let num2 = self.textField2.text.toInt() ?? 0
//演算
let numSign1 = self.switch1.on ? (-1) * num1 : num1
let numSign2 = self.switch2.on ? (-1) * num2 : num2
let total = numSign1 + numSign2
//表示
self.calcStr1.text = "\(numSign1)"
self.calcStr2.text = "\(numSign2)"
self.resultLabel.text = "\(total)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment