-2

I am trying to send the jsonData of the user as soon as he logged in to the next view controller and display some details in it. But I am unable to pass that jsonData. If I declare a global var in the firstViewController, I can pass it to secondViewController.

But I am declaring my let jsonData inside a condition and I am unable to send it. I tried retrieving all the details of json in global and share it in the secondViewController. But I can't as it can only retrieved inside the condition.

let jsonData:NSDictionary = NSJSONSerialization.JSONObjectWithData(urlData!, options:NSJSONReadingOptions.MutableContainers , error: &error) as NSDictionary
                let jsonArray: AnyObject! = jsonData.valueForKey("user")
                NSLog("jsonddata = \(jsonArray)")


 if (segue.identifier == "login_success") {
var svc = segue.destinationViewController as welcomeViewController;
    svc.userNameText =  userNameText.text
    svc.jsonArray = jsonArray
halfer
  • 19,824
  • 17
  • 99
  • 186
AAA
  • 1,957
  • 4
  • 23
  • 42
  • have you heard about the _model_ layer? or are you only familiar with the mixing of _view_ and _controller_ layers together in a `UIViewController` instance? – holex Oct 10 '14 at 11:34
  • no, i have not heard about that! i am only using controllers and views – AAA Oct 10 '14 at 17:51

1 Answers1

0

try like this

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if (segue.identifier == "login_success") {
        var svc = segue!.destinationViewController as secondViewController;

        svc.toPass = textField.text

    }
}
Alex Cio
  • 6,014
  • 5
  • 44
  • 74
Sport
  • 8,570
  • 6
  • 46
  • 65