What is preferred method of data storage?

Discussion in 'iPhone/iPad Programming' started by darkpegasus, Aug 29, 2008.

  1. macrumors newbie

    Joined:
    Jul 18, 2008
    #1
    This may seem like a stupid questions, but I couldn't find an example of it anywhere. Is there a specific way that user preferences should be stored?

    I basically have some simple attributes like a background image name that I would like to save and then load next time the user opens the app.
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    NSUserDefaults
     
  3. thread starter macrumors newbie

    Joined:
    Jul 18, 2008
    #3
    Awesome, thanks. And for those that might need more than a one-word reply (although it's amazing what one word can tell you):

    -(void)saveToUserDefaults:(NSString*)myString
    {
    NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];

    if (standardUserDefaults) {
    [standardUserDefaults setObject:myString forKey:mad:"Prefs"];
    [standardUserDefaults synchronize];
    }
    }

    -(NSString*)retrieveFromUserDefaults
    {
    NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
    NSString *val = nil;

    if (standardUserDefaults)
    val = [standardUserDefaults objectForKey:mad:"Prefs"];

    return val;
    }
     
  4. macrumors 6502

    Joined:
    Oct 4, 2003
    Location:
    NY
    #4
    I just save all the user info as an array within an NSData object on a file in documents directory.
     

Share This Page