Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 639315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:49:44+00:00 2026-05-13T20:49:44+00:00

Okay, of course it is possible, that’s no issue. In my code I have

  • 0

Okay, of course it is possible, that’s no issue. In my code I have multiple objects that I work with, and they need to be data persistent. To do that I’ve used object encoding and storing them in a data file. Such as:

-(NSString *)dataFilePath
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    return [documentsDirectory stringByAppendingPathComponent:kFilename];
}

And then further along in another section of code:

NSMutableData *data = [[NSMutableData alloc] init];
        NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
        NSLog(@"Test 4");
        [archiver encodeObject:playerTwo forKey:@"PlayerTwoObject"];
        [archiver encodeObject:singlePlayer forKey:@"SinglePlayer"];
        [archiver encodeObject:playerOne forKey:@"PlayerOneObject"];
        [archiver encodeObject:settings forKey:@"Settings"];


        [archiver finishEncoding];
        [data writeToFile:[self dataFilePath] atomically:YES];
        [singlePlayer release];
        [playerOne release];
        [playerTwo release];
        [settings release]; 

And that saves the objects. I know it works, because I can take them out with this code:

unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:[[NSMutableData alloc] initWithContentsOfFile:[self dataFilePath]]];
    SettingsObject *settings = [unarchiver decodeObjectForKey:@"Settings"];
    Player *test = [unarchiver decodeObjectForKey:@"PlayerOneObject"];
    NSLog(@"Power On Settings Test: %d,%d", [settings playerOneStartingLife], [settings singlePlayerStartingLife]);
    NSLog(@"Power On Player Test: %@,%d", [test name], [test life]);

Cool! So now I can store my objects, and read them out. So this is where the issue comes in. In a different class I take out one of the objects I’m storing and work with it. Not all of them, I only read out one. And then I save it again after I change the settings. But I only save it:

NSMutableData *data = [[NSMutableData alloc] init];
    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
    [archiver encodeObject:singlePlayer forKey:@"SinglePlayer"];
    [archiver finishEncoding];
    [data writeToFile:[self dataFilePath] atomically:YES];
    [singlePlayer release];

After I have done that, all the rest of the objects I have stored are removed. Now I’m confused, because I thought I was only editing the one key “SinglePlayer”, but apparently that somehow removes the rest of them? Is that supossed to happen? I have had some issues with releasing the archiver, would that affect it at all… I don’t think it would. Does anyone have some insight on this, because I don’t want to have to take all of the objects out and re-encode them if I only want to edit one of them…

Thanks for your help!

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:49:44+00:00Added an answer on May 13, 2026 at 8:49 pm

    You create a new archiver, with an emtpy data object. You write the SinglePlayer object in the data, but you do not store the rest of the data in the same, newly created archive.

    To do so, unarchive the whole previously stored archive, then adjust the SinglePlayer object and archive and save it again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so i have a semi weridish problem with re.sub. Take the following code:
Okay so you have and array A[]... that is passed to you in some
Okay basically I am creating a stored procedure that will return data for our
assume i have a huge input form, which of course representing classes. i need
Okay, strange question time! I'm refactoring some old C++ code that declares a bunch
Okay, This may be really simple or it may not even be possible, or
Okay, I have done a bit of searching online and found this thread, but
Okay people, I'm sure someone has had this issue and can help me out.
Okay, so I have torn what I had down and am rebuilding it, here's
Okay, the specs have changed on this one somewhat. Maybe someone can help me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.