1. Model Class
class TestModel{
var name : String!
var age : String!
init(name : String!, age : String!) {
self.name = name
self.age = age
}
}
2. View Controller
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var name: UITextField!
@IBOutlet weak var age: UITextField!
@IBOutlet weak var nameLbl: UILabel!
@IBOutlet weak var ageLbl: UILabel!
var SavedData : TestModel!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func saveData(_ sender: Any) {
let vName : String = name.text!
let vAge : String = age.text!
SavedData = TestModel(name: vName, age: vAge)
print(SavedData.name)
}
@IBAction func showData(_ sender: Any) {
nameLbl.text = SavedData.name
ageLbl.text = SavedData.age
}
}