title: How to pass JSON data to another view controller from login function using post method?
body: <p>I m having blank data in another view controller, I can pass data between table view controller but I m having a problem to parse data from login method and pass access token or username from JSON?</p>
  
  <pre><code> @IBOutlet weak var username_textfield: UITextField!
      @IBOutlet weak var password_textfield: UITextField!
  var logindata : [Login] = []
   var myResponse  :   JSON    =   nil
  func getlogin(){
          let headers = [
              "Content-Type": "application/x-www-form-urlencoded"
          ]
          let parameters = [
  
              "UserName": username_textfield.text! as String,
              "Password": password_textfield.text! as String,
              "grant_type": "password",
              ]
  
  
          //        let url = NSURL(string: "http://192.168.100.5:84/Token")!
          Alamofire.request("http://192.168.100.5:84/Token", method: .post, parameters: parameters, encoding:  URLEncoding.httpBody, headers: headers).responseJSON { (response:DataResponse&lt;Any&gt;) in
  
              switch(response.result) {
              case.success(let data):
                  print("success",data)
                   let statusCode = (response.response?.statusCode)!
                  if statusCode == 200{
                      self.view.makeToast(message: "Welcome !!")
                      self.performSegue(withIdentifier: "mainview", sender: self)
  
                  }else{
                      self.view.makeToast(message: "Username or password invalid")
                  }
                  self.myResponse = JSON(data)
              let login = Login(loginJson: self.myResponse)
              DispatchQueue.main.async(execute: { () -&gt; Void in
                  self.performSegue(withIdentifier: "pass_data", sender: login)
              })
  
  
              case.failure(let error):
                  print("Not Success",error)
              }
  
          }
      }
  </code></pre>
  
  <p><strong>passing data to another view controller</strong> </p>
  
  <pre><code>    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
      if segue.identifier == "pass_data" {
          if let eventsVC = segue.destination as? MenuDrawerViewController,
              let loginData = sender as? Login {
              eventsVC.login_details = loginData
          }
      }
  }
  </code></pre>
  
  <p><strong>i have model class</strong> </p>
  
  <pre><code>class Login{
  
      var access_token = String()
      var token_type = String()
      var expire_in = String()
      var username = String()
      var masterid = String()
      var name = String()
      var access = String()
      var issued = String()
      var expries = String()
  
      init(loginJson:JSON){
      self.access_token = loginJson["access_token"].stringValue
          self.token_type = loginJson["token_type"].stringValue
          self.expire_in = loginJson["expires_in"].stringValue
          self.username = loginJson["userName"].stringValue
          self.masterid = loginJson["MasterID"].stringValue
          self.name = loginJson["Name"].stringValue
          self.access = loginJson["Access"].stringValue
          self.issued = loginJson[".issued"].stringValue
          self.expries = loginJson[".expires"].stringValue
      }
  
  
  }
  </code></pre>
  
  <p><strong>and in second view controller I have call class like  this</strong></p>
  
  <pre><code>class MenuDrawerViewController: UIViewController {
  var login_details : Login?
   override func viewDidLoad() {
          super.viewDidLoad()
  
  
  
          titlename_text.text = login_details?.name
          // Do any additional setup after loading the view.
      }
  }
  </code></pre>
  
  <blockquote>
    <p>I m a bit confused where I'm getting wrong or I'm doing it in wrong
    way, how it can be solved?</p>
  </blockquote>
  
  <p>i want to pass data through navigation controller and without using navigation controller data is passed so i try this function to pass and it giving me error on "<code>if let detailController</code>" condition </p>
  
  <pre><code>override  func prepare(for segue: UIStoryboardSegue, sender: Any?) {
          if segue.identifier == "dashboard" {
              let navController = segue.destination as! UINavigationController
             if let detailController = navController.topViewController as! ViewController,
              let loginData = sender as? Login {
                  detailController.login_details = loginData
              }
          }
      }
  </code></pre>