Login viewcontroller best practice

Hi,


I am coding with Swift, ios 9.


I have an app that when a button is clicked to go to viewcontroller X, I must force the user to login, if he has not already done so.


In storyboard, I already have a segue from the button to viewcontroller X.


But, before allowing the user to go to viewcontroller X, I must first programmatically inject the login viewcontroller so that he can log in.


Then, once the user is logged in, I must then segue to viewcontroller X, which is where he wanted to go initially.


The above scenario is what I believe needs to be done.


Are there any samples and/or best practices on how such functionality should be implemented.


I will need this type of functionality whenever a user is trying to access a viewcontroller to which he must first be logged in.


Thanks

Replies

I'd have the target view controller check whether or not you're authenticated in viewDidAppear and if not, then modally present the login window.

Thanks.


If the user cancels from the Login ViewController, I try to unwind to the original ViewController, bypassing ViewController X.


An error is given "Unbalanced calls to begin/end appearance transitions for ViewController X".


This seems to occur because the appearance of ViewController X may not have fully completed and it was skipped durin the unwind.


Thoughts?