Parse Tutorial: Getting Started with Web Backends

Get started with Parse, and learn how to set up your iOS app with a backend that lets you store user accounts, posts, and attachments! By Ron Kliffer.

Leave a rating/review
Save for later
Share
You are currently viewing page 5 of 5 of this article. Click here to view the first page.

Staying Logged In and Logging Out

YYou probably noticed that every time the app launches, the user needs to log in again. Also, the “Log Out” button just takes you back to main screen and it doesn’t actually log you out.

In this final part of the tutorial you’ll create code to keep the user logged in between app launches, and also provide an option to actually log out of the server.

First, go to LoginViewController.swift and add the following to viewDidLoad():

//Check if user exists and logged in
if let user = PFUser.currentUser() {
  if user.isAuthenticated() {
    self.performSegueWithIdentifier(scrollViewWallSegue, sender: nil)
  }
}

When a user logs in to your app, Parse will save the user and their state between app launches. Here you check, using optional binding, if the user exists. If so, you check if the user is authenticated, and if so, then navigate to the posts wall.

To let a user log out, go to WallPicturesTableViewController.swift and find logOutPressed(_:). Replace it with the following:

@IBAction func logOutPressed(sender: AnyObject) {
  PFUser.logOut()
  navigationController?.popToRootViewControllerAnimated(true)
}

Here you simply log out the user and navigate back to the initial login screen. Do the same in WallPicturesViewController.swift.

Build and run, and you’re done! :]

Where To Go From Here?

Here is the complete example project you developed in the above tutorial.

You’ve seen how easy it is to upload and download objects based on a PFObject subclass, and how to work with PFUsers in Parse!

There is so much more you can do with Parse. Parse also lets you send push notifications to your users directly from within your app, add various social features that are already embedded in the framework, and add analytics so you track your users’ every move.

Parse also offers more advanced features like writing cloud code and schedule recurring jobs for the backend.
As you go along with writing your Parse apps, and get more familiar with it, I highly recommend you explore more of these features.

At this point, you’re likely inspired to add some backend functionality to a project that could benefit from it; or perhaps a cloud app you thought was going to be too hard is now within reach! :]

I hope to see some apps made from you with Parse in the future. If you have any questions or comments, please join the forum discussion below! :]