• Neno83


    You said in video 2 you will create a video showing hot to avoid the shortly appearing of the protected page before login.

    How to do that?

    Thank you very much
    Best regards

  • sephethus

    What if the user has just installed the app and the boolForKey isn’t created yet? Then there is no bool to determine whether they are logged in.

    • Then, initial ViewController should launch.

      • sephethus

        Figured out the default bool for a key that isn’t created yet is false, so the login launches.

        • iKhalil


          //Initializing defaults

          “IsUserLoggedIn” : false,

          in your AppDelegate.swift file ?

  • Chris Brown

    Hi, thanks for a great tutorial, it works great. Just wondered if you could help with this question:- I want to have 2 buttons on the protected page which are both disabled by default and then when the user has logged in ( a boolean value is retrieved from database) and we dismiss the login view controller, one of the buttons on the protected page is enabled dependent on the boolean value. How would I pass this value back to the protected page? Thanks, any help you can give is greatly appreciated

    • You can declare a property(variable) in your protected page. And then set this variable from the login view just before you are taking user to protected page. For example:

      let protectedPage = self.storyboard?.instantiateViewControllerWithIdentifier(“ProtectedPageViewController”) as! ProtectedPageViewController

      protectedPage.myBoolVar = true;

      let protectedPageNav = UINavigationController(rootViewController: protectedPage)

      let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate

      appDelegate.window?.rootViewController = protectedPageNav

      • Chris Brown

        Thank you, I shall give it a try :-))

  • Nathan Berhe

    Hey sergey, how do i change the initial viewcontroller programmatically if the user for example log in, i want the next view to always load up first and if user log out i want the login viewcontroller to load up first?

  • Lyheang IBell

    var error:NSError?
    var json = NSJSONSerialization.JSONObjectWithData(data, optionsns:.MutableContainers, error: &error) as NSDictionary

    I got message error: => error: &error I used swift 2+ and IOS 9+ please help me fix this

  • Emrah Erten

    I have the same error and im new on swift and ios app developing. I didnt combine the error and the example code part. I didnt find where is the problem and how can i write the code to solve. Is it possible to help?
    Using Swift 3

    var error:NSError?
    var json = NSJSONSerialization.JSONObjectWithData(data, optionsns:.MutableContainers, error: &error) as NSDictionary

    This is your code on video:

    let err: NSError?
    let json = JSONSerialization.JSONObjectWithData(data, options: .mutableContainers, error: &err) as? NSDictionary

    if let parseJSON = json {
    let resultValue = parseJSON[“status”] as? String
    print(“result: (String(describing: resultValue))”)

    var isUserRegistered:Bool = false;
    if(resultValue==”Success”) { isUserRegistered = true; }

    var messageToDisplay:String = parseJSON[“message”] as! String!;
    messageToDisplay = parseJSON[“message”] as! String!;


    DispatchQueue.main.async(execute: {

    // Display Alert message with confirmation.
    let myAlert = UIAlertController(title: “Alert”, message: messageToDisplay, preferredStyle: UIAlertControllerStyle.alert);

    let okAction = UIAlertAction(title:”Ok”, style:UIAlertActionStyle.default) { action in
    self.dismiss(animated: true, completion:nil);

    self.present(myAlert, animated:true, completion:nil);



    This is the code in your example:
    let jsonText = “{“first_name”:”Sergey”}”
    var dictonary:NSDictionary?

    if let data = jsonText.data(using: String.Encoding.utf8) {

    do {
    dictonary = try JSONSerialization.jsonObject(with: data, options: []) as? [String:AnyObject]

    if let myDictionary = dictonary
    print(” First name is: (myDictionary[“first_name”]!)”)
    } catch let error as NSError {

    But how can i write the example code like your code in the video for user login and register system?


  • sravan kumar

    hai nice tutorial but when i am working in my swift 3 it was showing errors