0

For example, I have an entity named Profile with attributes like

name,
gender,
dateOfBirth,
height,
weight,
bloodGroup,
province,
country,
picture

But, I am going to use a single profile for the whole app. So I think I don't need to persist this object into core data. So is it a good practice to store all attributes in NSUserDefaults? My app may store other fields in the NSUserDefaults too. Is it a good thing to store many values into NSUserDefaults? Otherwise any other idea would be appreciated.

Dinesh Raja
  • 8,501
  • 5
  • 42
  • 81

3 Answers3

1

You can store values in NSUserDefaults but make sure to add conditions while getting them maybe other users wants to login, like you can erase everything on logout and save on login. Or you can store values in a PList file.

ThePunisher
  • 410
  • 1
  • 4
  • 14
0

You can use NSUserDefaults as there is no information which is confidential, if any information is confidential, you should save values in KeyChain.

You can use NSDictionary and store that dictionary directly into NSUserDefaults, this will help you access data more easily.

Visit this link on how to do that.

Hope this info helps you..

Community
  • 1
  • 1
P.J
  • 6,547
  • 9
  • 44
  • 74
-2

iPhone SDK has a very elegant way of saving user settings in a structure called as NSUserDefaults. You can add a bunch of different objects in this UserDefaults – These are nothing but a dictionary of user settings that you will save in the app’s document folder.

Using NSDictionary user can store store data.

NSMutableDictionary *dic = [[NSMutableDictionary  alloc] init];

[dic addObject:@"name" forKey:@"objProfile"];
[dic addObject:@"gender" forKey:@"objProfile"];

[NSUserDefaults standardDefaults] setObject:dic forKey:@"Profile"];

Another solution is to store data in PList. This is the best way to store data.

Hope this will help you.

Nirav Jain
  • 5,088
  • 5
  • 40
  • 61