Zita Noriega Estrada Zita Noriega Estrada - 1 year ago 86
iOS Question

How can I pass data from a VC to another in Swift 3 without a segue?

I have an issue passing data trough a segue because I'm using protocols to show my data. But I need to find a way to pass the data I have in a View Controller to a second one. The big issue is that I need the information in Swift 3 because the solutions that I have found are only in Onjective-C.

Well, please forget the example that I showed you. The only thing that I need to do is to pass the information inside a uilabel in my first View Controller to another uilabel in the second View Controller but without using a segue.

So I would really appreciate if somebody has a solution in Swift 3.

Thanks in advance!

Answer Source

You can pass data with Navigation in Swift 3 like this: -

Current Class

 let editProfile = self.storyboard?.instantiateViewController(withIdentifier: "editProfile") as? EditProfileVc
        if detailsModel.count != 0 {
            editProfile?.accModel = detailsModel[0] //Passing data here with the array
 self.navigationController?.pushViewController(editProfile!, animated: true)

and target class (here using model class variable)

    class EditProfileVc: BaseNotifyM, PickerDelegate {

        // Data Variable 
        var accModel:AccountModel? //-- Here you can use [String] or [[String: Any]] or as per you choice for data passing 

      //MARK: - Life Cycle
       override func viewDidLoad() {

        //Do some thing with your data

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download