Aboogie Aboogie - 1 year ago 121
iOS Question

iOS Build one View

I am building an app(swift iOS9) that requires login and of course it has multiple views after login. Is there a way to only build and run one view that is after the login so that I don't have to enter login information every time?


Answer Source

I assume you're asking how to show different view controllers at launch (ie. login the first time, some other view subsequently). Something along the lines of (untested code):

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let firstVC = (shouldLogin) ? "LoginVC" : "OtherVC"
    let vc = storyboard.instantiateViewControllerWithIdentifier(firstVC)
    self.window?.rootViewController = vc
    return trud

Then NSUSerDefaults is commonly used to store the fact they're logged in, which you can read and set "shouldLogin" appropriately.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download