Protocol with registartion form

//  ViewController.swift
//  ProtocolRegistrationForm

import UIKit

class ViewController: UIViewController,BackDataTransfer {
    
    var arrData = NSMutableArray()
    var swtBool = Bool()
    var dicData = NSMutableDictionary()
    @IBOutlet var OutletSwtGender: UISwitch!
    @IBOutlet var txtBirthDate: UITextField!
    
    @IBAction func swtGender(_ sender: UISwitch) {
        
        if sender.isOn == true
        {
            lblGender.text = "Male"
            swtBool = true
            
        }else
        {
            lblGender.text = "Female"
            swtBool = false
        }
        
        
    }
    @IBOutlet var lblGender: UILabel!
    @IBOutlet var txtPhone: UITextField!
    @IBOutlet var txtEmail: UITextField!
    @IBOutlet var txtName: UITextField!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        OutletSwtGender.isOn = true
        lblGender.text = "Male"
    
        dicData = ["Name":"","Email":"","phone":"","Gender":"Male","isOn": true,"birthDate":""] as NSMutableDictionary
        arrData.add(dicData)
        
        
        txtName.text = (arrData[0] as! NSMutableDictionary).value(forKey: "Name") as? String
        txtEmail.text = (arrData[0] as! NSMutableDictionary).value(forKey: "Email") as? String
        txtPhone.text = (arrData[0] as! NSMutableDictionary).value(forKey: "phone") as? String
        lblGender.text = (arrData[0] as! NSMutableDictionary).value(forKey: "Gender") as? String
           //cell.swt.isOn = (dict["isOn"] as! Bool?)!
       OutletSwtGender.isOn = ((arrData[0] as! NSMutableDictionary).value(forKey: "isOn") as? Bool)!
        txtBirthDate.text = (arrData[0] as! NSMutableDictionary).value(forKey: "birthDate") as? String
        
        }

    func arrBackData(arr: NSMutableArray) {
        print("arrBack = \(arr)")
        arrData.removeAllObjects()
        arrData = arr
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func btnSave(_ sender: UIButton) {
        
        
        dicData["isOn"] = swtBool as AnyObject?
        dicData["Name"] =  txtName.text as AnyObject?
        dicData["Email"] = txtEmail.text
        dicData["phone"] = txtEmail.text
        dicData["Gender"] = txtEmail.text
        dicData["birthDate"] = txtEmail.text
        arrData.replaceObject(at: 0, with: dicData)
        
        
        
        let SVC : SecondViewController = self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as! SecondViewController
        SVC.arrGet = arrData
        SVC.delegate = self
        self.navigationController?.pushViewController(SVC, animated: true)

        
        
    }

    @IBAction func btnReset(_ sender: UIButton) {
        txtName.text = ""
        txtEmail.text = ""
        txtPhone.text = ""
        txtBirthDate.text = ""
        OutletSwtGender.isOn = true
    }
}






//  SecondViewController.swift
//  ProtocolRegistrationForm
//
//  Created by agile-10 on 03/10/17.
//  Copyright © 2017 agile. All rights reserved.
//

import UIKit
protocol BackDataTransfer{
    func arrBackData(arr: NSMutableArray)
}

class SecondViewController: UIViewController {

    @IBOutlet var txtName11: UITextField!
    
    var arrGet = NSMutableArray()
    
    var delegate: BackDataTransfer? = nil
    
    var swtBool1 = Bool()
    
    
    @IBOutlet var swtgender1: UISwitch!
    @IBOutlet var lblGender1: UILabel!
    @IBOutlet var txtBirthDate1: UITextField!
    @IBOutlet var txtPhone1: UITextField!
    @IBOutlet var txtEmail1: UITextField!
   
    override func viewDidLoad() {
    super.viewDidLoad()
    print(arrGet)
        
       txtName11.text = (arrGet[0] as! NSMutableDictionary).value(forKey: "Name") as? String
       txtEmail1.text = (arrGet[0] as! NSMutableDictionary).value(forKey: "Email") as? String
       txtPhone1.text = (arrGet[0] as! NSMutableDictionary).value(forKey: "phone") as? String
        txtBirthDate1.text = (arrGet[0] as! NSMutableDictionary).value(forKey: "Gender") as? String
        
        if arrGet[4] as! Bool == Bool(booleanLiteral: true)
        {
            swtgender1.isOn = true
        }
        else
        {
            swtgender1.isOn = false
        }
        
        
       lblGender1.text = (arrGet[0] as! NSMutableDictionary).value(forKey: "Gender") as? String
        
        
        
        
        
        
        // Do any additional setup after loading the view.
    }

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

    @IBAction func swtGenderAction1(_ sender: UISwitch) {
        
        
        if sender.isOn == true
        {
            lblGender1.text = "Male"
            swtBool1 = true
            
        }else
        {
            lblGender1.text = "Female"
            swtBool1 = false
        }

    }
    
    
    @IBAction func btnEdit(_ sender: UIButton) {
        arrGet.add(txtName11.text!)
        arrGet.add(txtEmail1.text!)
        arrGet.add(txtPhone1.text!)
        arrGet.add(txtBirthDate1.text!)
        arrGet.add(String(swtBool1))
        arrGet.add(lblGender1.text!)
        print(arrGet)
        
        delegate?.arrBackData(arr: arrGet)
        print(delegate?.arrBackData(arr: arrGet)
)
        
        self.navigationController?.popViewController(animated: true)
        
    }
    
    
}

Comments