!I have been stuck for 2 days on this issue. Here is my scenario.
User clicks login button, if email address and password are stored in UserDefaults
, the app silently login the user in, first presenting an UIAlertController
while retrieving the user's data from the server. Once the data is returned to the app, a completion handler assigns a local property var User: [String: AnyObject]
the results. I can print(self.User)
at this point and the data is properly assigned. All good. The problem occur when I try to pass this data to the next controller that I am presenting via present
. Here is my code:
LoginViewController.swift
-----
dismiss(animated:true, completion: {
let tenantViewController = storyboard.instantiateViewController(withIdentifier :"tenantDashboardViewController") as! TenantDashboardViewController
tenantViewController.User = user
print(tenantViewController.User) //Works
self.present(tenantViewController, animated: true)
})
Here is my destination viewcontroller
import Foundation
import SideMenuController
class TenantDashboardViewController: SideMenuController {
var User: [String: AnyObject]?
override func viewDidLoad() {
super.viewDidLoad()
performSegue(withIdentifier: "showTenantDashboardHomeViewController", sender: nil)
performSegue(withIdentifier: "containTenantSideMenu", sender: nil)
print(self.User!) //Always returns nil, crashes app
}
}
Thanks in advance!