Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Arun Chiluveru
2,049 Pointsdimiss view controller and present another using NSNotificationCenter Swift3
Please help me out in dismissing a modal view controller and presenting main root controller using NSNotificationCenter. I am doing in the following way
ONEVIEWCONTROLLER
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(ForgotPasswordViewController.dimissController), name: NSNotification.Name.poptologin, object: nil)
}
func dimissController(){
let mvc = self.storyboard?.instantiateViewController(withIdentifier: StoryboardIdentifier.LoginViewController.rawValue) as! LoginViewController
self.navigationController!.popViewController(animated: true)
}
extension Notification.Name {
static let poptologin = Notification.Name("PopToLogin")
}
MODALVIEWCONTROLLER
@IBAction func ResetButtonAction(_ sender: Any) {
self.dismiss(animated: true, completion: {
DispatchQueue.main.async(execute: { () -> Void in
NotificationCenter.default.post(name: NSNotification.Name.poptologin, object: nil)
})
})
}
In the above code LoginViewController(Main rootviewcontroller) and i am trying to present LoginViewController by dismissing the modal view. Please correct me if i am wrong and if the approach is wrong please point me in right direction