What is the file path to use for NSKeyedArchiver: archiveRootObject:toFile

Discussion in 'iOS Programming' started by yalag, Aug 14, 2008.

  1. yalag macrumors 65816

    Joined:
    Nov 18, 2007
    #1
    Trying to save some objects to file on the iphone, this method seems
    to be the way to do it NSKeyedArchiver:archiveRootObject:toFile but
    not sure what the file path should be. I tried a single filename
    "test" and it got created at /test on my desktop which is probably not
    going to work on real devices. Any ideas?
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Here is code for getting the absolute path of "test" inside the application's documents folder (you can read more about this in the iPhone programming guide):
    Code:
    NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *filename = [docsPath stringByAppendingPathComponent:@"test"];
     
  3. yalag thread starter macrumors 65816

    Joined:
    Nov 18, 2007
  4. Hardan macrumors newbie

    Joined:
    Nov 10, 2008
    #4
    Still having it wrong

    this is kinda noobish but i still seem to be unnable to archieve an object... I have this object, called scoreKeeper (member of the ScoreKeeper class i designed. It conforms to NSCoding and all) but i can`t seem to encode it =/

    should i create the test file explicidly or something?

    This is what i do:

    NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *filename = [docsPath stringByAppendingPathComponent:mad:"test"];
    BOOL result = [NSKeyedArchiver archiveRootObject: scoreKeeper toFile: filename];
     

Share This Page