Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Check for Login without connection to database in Swift App

Hey,

I'm building an iPhone App and there is a problem.

I want to check if you have successfully logged in without a connection to the database.

So first it lets you log in and second it proves if you have successfully logged in by checking if there is the option "Logout" on the Page (Which is usually just there if you are logged in)

So do you have an idea how to handle that?

1 Answer

Not sure I understand your question, but it sounds like you want to locally store the login state for your user (presumably you will connect to the db to actually log the user in).

You have several options for locally storing state. Core data, a plist file, a SQLite database, or NSUserDefaults. The last one is the quickest to set up, although you may already be using core data to store other information about a User entity, in which case I would just add a loggedIn property to that entity.

Whichever you choose, you'll simply add the logic to set the loggedIn state in your login and logout methods.

Hope this helps!

-Greg