-1

I have 2 ViewControllers and 2 classes for each of them.

In ViewController1, I have a dictionary(named 'data' of type [String:String]) containing user emailID, Password, First Name and Last Name.

I want to access this 'data' dictionary in the class of ViewController2 and append a few more elements (Age and Gender).

I tried to do this by creating instances of ViewController1 class to access the data and segue. When I'm printing the 'data' dictionary in the console before appending it is showing up empty and if I'm printing it after appending its only showing the latest elements in the dictionary (i.e. only age and gender)

How to pass the dictionary between classes so that it's elements also move with it and not just an empty dictionary ?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Akshay Yerneni
  • 103
  • 2
  • 11
  • can you show your tried code – Ram Feb 20 '17 at 07:29
  • Also see, [Stackoverflow Documentation on Passing Data between ViewControllers](http://stackoverflow.com/documentation/ios/434/passing-data-between-view-controllers#t=201702200732185412699) . – NSNoob Feb 20 '17 at 07:32
  • This can be helpful : http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers – Priyal Feb 20 '17 at 07:33

1 Answers1

0

Try this -

  override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if (segue.identifier == "segueName") { // your segue name
        //get a reference to the destination view controller
        let destinationVC = segue.destination as! FirstViewController

        //set properties on the destination view controller
        destinationVC.dict = data //
        //etc...
    }
}

Note - Create a variable in your destination view controller.

Prema Janoti
  • 836
  • 5
  • 18
  • yes !!! propertiy – Prema Janoti Feb 20 '17 at 07:36
  • I've tried this, but still the dictionary going into the 2nd ViewController is showing as an empty dictionary :/ – Akshay Yerneni Feb 20 '17 at 07:40
  • 1
    @AkshayYerneni What's holding you back from trying multiple ways described in the answer of the dupe question? Or on Documentation? This is actually one way to go about it. If you can't get it to work, then there's something wrong in your code, not in this answer\ – NSNoob Feb 20 '17 at 07:50