xcode: save a Label value

0

I can not find the solution that works for me.

@IBOutlet weak var N1: UITextField!
@IBOutlet weak var N2: UITextField!


@IBOutlet weak var P1: UITextField!
@IBOutlet weak var P2: UITextField!


@IBOutlet weak var F1: UILabel!
@IBOutlet weak var F2: UILabel!


@IBOutlet weak var res1: 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 total(_ sender: Any) {


   let n1 = Double(N1.text!)
   let p1 = Double(P1.text!)
   let f1 = Double(n1! + p1!)

    F1.text = "\(f1)"


    let n2 = Double(N2.text!)
    let p2 = Double(P2.text!)
    let f2 = Double(n2! + p2!)

     F2.text = "\(f2)"        


    res1.text = "\(res1)"

How can I do to take the results that I get in Label ( F1.text / F2.text ) and add them again, appearing in another Label ( res1 )? (All by clicking the same button)

idea:

2+2=4
1+2=3

4+3=7
    
asked by Marina Ad 24.03.2017 в 11:15
source

1 answer

1

Hello, try this to see if it works for you

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var F1: UILabel!
    @IBOutlet weak var F2: UILabel!
    @IBOutlet weak var rest: UILabel!



    override func viewDidLoad() {
        super.viewDidLoad()
        F1.text = "1.23"
        F2.text = "2.00"
    }


    @IBAction func presionarBoton(_ sender: Any) {
        guard let f1 = Double(F1.text!), let f2 = Double(F2.text!) else {
            return
        }

        let suma = f1 + f2
        self.rest.text = String(suma)

    }

}

    
answered by 25.03.2017 / 01:56
source