title: keep user logged in ios app swift
body: <p>I have made app which include login and signup functionality. When I run my app at that time login and other functionality everything is going ok but when I stop my app and run it again login page showing again can I make user logged in when again app launch. Below is my code which I have used in my app.</p>
  
  <pre><code>override func viewDidAppear(animated: Bool) {
      super.viewDidAppear(true)
  
      let prefs:NSUserDefaults = NSUserDefaults.standardUserDefaults()
      let isLoggedIn:Int = prefs.integerForKey("ISLOGGEDIN") as Int
      if (isLoggedIn != 1) {
          self.performSegueWithIdentifier("goto_login", sender: self)
      } else {
          self.usernameLabel.text = prefs.valueForKey("USERNAME") as? String
      }
  }
  
  
  import UIKit
  
  @UIApplicationMain
  
  class AppDelegate: UIResponder, UIApplicationDelegate {
  
      var window: UIWindow?
  
      func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -&gt; Bool {
  
          // Override point for customization after application launch.
  
          /*
  
          var rootViewController = self.window!.rootViewController
  
          let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main" , bundle: nil)
  
          var isUserLoggedIn:Bool = NSUserDefaults.standardUserDefaults().boolForKey("isUserLoggedIn")
          if(!isUserLoggedIn){
              var loginViewController = mainStoryboard.instantiateViewControllerWithIdentifier("loginview") as! LoginViewController
  
              window!.rootViewController = loginViewController
              window!.makeKeyAndVisible()
  
          }else{
              var protectedPage = mainStoryboard.instantiateViewControllerWithIdentifier("profail") as! ProfailViewController
              window!.rootViewController = protectedPage
              window!.makeKeyAndVisible()
  
          }
  
          */
  
          return true
      }
  
      func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -&gt; Bool {
  
          return true 
      }
  }
  </code></pre>