Simple Calculator UItextField Two Input Swift 4


This time is a little example for code calculator, using only simple code, ok try to see the script below, you can try it quite simple.


//from original data



import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var label1: UITextField!
    @IBOutlet weak var label2: UITextField!
    
    @IBOutlet weak var sum: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        
     
    }
    @IBAction func multiplied(_ sender: UIButton) {
        self.sum.text = String(Int(label1.text!)! * Int(label2.text!)!)
    }
    
    @IBAction func divided(_ sender: UIButton) {
        self.sum.text = String(Int(label1.text!)! / Int(label2.text!)!)
    }
    
    @IBAction func plus(_ sender: UIButton) {
        
        self.sum.text = String(Int(label1.text!)! + Int(label2.text!)!)
        // example another way
        let toint = Int(label1.text!)!
        let toint2 = Int(label2.text!)!
        let toString = String(toint + toint2)
        self.sum.text = toString
    }
    
    @IBAction func subtracted(_ sender: UIButton) {
        self.sum.text = String(Int(label1.text!)! - Int(label2.text!)!)
    }
}

5 comments:

  1. I just thought it may be an idea to post incase anyone else was having problems researching but I am a little unsure if I am allowed to put names and addresses on here. 140 lbs to kg

    ReplyDelete
  2. I will really appreciate the writer's choice for choosing this excellent article appropriate to my matter.Here is deep description about the article matter which helped me more. online antiderivative calculator

    ReplyDelete
  3. Excellent Blog, I like your blog and It is very informative. Thank you
    Best online swift course
    Ranorex Online Training

    ReplyDelete
  4. The wooden framed machine came with wires into which beads were to be assembled for calculation purposes. Interestingly,matrix calculator these calculators were used in offices for quite a long time for easy and normal calculations. But, limited in their functionalities, they were sidelined and thus came other forms of calculators into the picture.

    ReplyDelete