Pass value from one scene to other in iOS app using Swift

Code of ViewController (code of file from where you want to pass value):

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var txt1: UITextField!
    override func viewDidLoad() {
        super.viewDidLoad()
       
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
      
    }

    @IBAction func ClickToPass(_ sender: Any) {
        let mmi  = self.storyboard?.instantiateViewController(withIdentifier: "Second") as! SecondViewController
       
        mmi.passedvalue = txt1.text!
        self.navigationController?.pushViewController(mmi, animated: true)
    }
    

}


Code of SecondViewController (code of file where you want to get value):

import UIKit

class SecondViewController: UIViewController {

    @IBOutlet weak var label1: UILabel!
    var passedvalue = String()
    override func viewDidLoad() {
        super.viewDidLoad()

        label1.text = "Passed value= " + passedvalue
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}


Screenshots:



Develop an iPhone application that convert birth date into year, month and days in swift.

Code:

ViewController.swift:


import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var lblday: UILabel!
  
    @IBOutlet weak var view1: UIView!
    @IBOutlet weak var lblmonth: UILabel!
    @IBOutlet weak var lblyear: UILabel!
    @IBOutlet weak var txtdate: UITextField!
    override func viewDidLoad() {
        super.viewDidLoad()
        view1.isHidden = true
    }

    @IBAction func btnClicked(_ sender: Any) {
        view1.isHidden  = false
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "dd/MM/yyyy"
        let date = dateFormatter.date(from: txtdate.text!)
        let NumOfDays: Int = daysBetweenDates(startDate: date!, endDate: Date())
        let year = NumOfDays/(365)
        let month =  (NumOfDays - (year * 365))/30
        let days = NumOfDays - (year * 365 + month * 30)
        lblyear.text = "\(year)"
        lblmonth.text = "\(month)"
        lblday.text = "\(days)"
    }
    func daysBetweenDates(startDate: Date, endDate: Date) -> Int {
        let calendar = Calendar.current
        let components = calendar.dateComponents([Calendar.Component.day], from: startDate, to: endDate)
        return components.day!
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

Result: