Ryan Bobrowski
Ryan Bobrowski

Reputation: 2730

iOS - Saving logged in user info

So in my app I have a master view controller which checks whether or not NSUserDefaults.standardUserDefaults().objectForKey("userLoggedIn") == nil or not. If it's nil, it presents the authentication view controller (login ,register, etc.). Otherwise, the app is initialized.

My question is - should I be storing user information? I'm not talking about secure stuff like a password or an API key which I would use keychain for, I'm just talking the user's id, name, avatar, etc (represented in a User model). Is it good practice to store this locally so I don't have to keep hitting the server for it every time (since the app relies on this information), and if so, what's the best way to store someting lightweight yet important like this? NSUserDefaults again? NSKeyedArchiver?

Upvotes: 2

Views: 644

Answers (1)

zaph
zaph

Reputation: 112865

Use NSKeyedArchiver. Then you will have a Data Model class and can access the items directly via properties instead by a String name, the compiler will help ensure there are no typos.

Upvotes: 2

Related Questions