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 6869763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:35:55+00:00 2026-05-27T03:35:55+00:00

I’m trying to save the objects called blobs using NSKeyedArchiver. I use NSMutableData and

  • 0

I’m trying to save the objects called blobs using NSKeyedArchiver.
I use NSMutableData and NSKeyedArchiver to save the data onto a file that represents that object. then I use NSData and NSKeyedUnarchiver to get the data from the files.

It seems to work out fine with no errors but when I load it all of the properties are “0” or nil.

Why is this?

-(void) LoadBlobs
{
    [blobs release];
    blobs = nil;
    blobs = [[NSMutableArray alloc]init];
    NSNumber *blobAmounts = [[NSUserDefaults standardUserDefaults]objectForKey:blobAmount];

    if([blobAmounts intValue] <= 0)
    {
        return;
    }

    for(int i = 0; i < [blobAmounts intValue]; i++)
    {
        NSLog(@"Loading Blob #%i...", i);
        NSString *curBlobDirectory = [[NSString alloc]initWithFormat:@"%@%i", saveDirectoryBlobs, i];
        NSLog(@"Blob directory is: %@", curBlobDirectory);

        NSData *blobData = [[NSData alloc]initWithContentsOfFile:curBlobDirectory];
        NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc]initForReadingWithData:blobData];

        Blob *b = [[Blob alloc]initWithFile:@"Blob.png"];
        b.position = CGPointMake([[unarchiver decodeObjectForKey:@"x"]intValue], [[unarchiver decodeObjectForKey:@"y"]intValue]);
        b.health = [[unarchiver decodeObjectForKey:@"health"]intValue];
        b.mating = [[unarchiver decodeObjectForKey:@"mating"]intValue];
        b.aiEntity = [[unarchiver decodeObjectForKey:@"entity"]intValue];
        b.action = [[unarchiver decodeObjectForKey:@"action"]intValue];
        b.faction = [[unarchiver decodeObjectForKey:@"faction"]intValue];
        b.equippedHelmet = [[unarchiver decodeObjectForKey:@"helmet"]boolValue];
        b.equippedSpear = [[unarchiver decodeObjectForKey:@"spear"]boolValue];
        b.goingTo = CGPointMake([[unarchiver decodeObjectForKey:@"gx"]intValue], [[unarchiver decodeObjectForKey:@"gy"]intValue]);
        b.homeID = [[unarchiver decodeObjectForKey:@"home"]intValue];
        b.aiID = [[unarchiver decodeObjectForKey:@"ai"]intValue];
        b.iD = [[unarchiver decodeObjectForKey:@"id"]intValue];

        NSLog(@"Blob #%i properties are: %f, %i, %i, %i, %i, %i, %i", i, b.health, b.mating, b.aiEntity, b.faction, b.action, b.equippedHelmet, b.equippedSpear);

        [blobs addObject:b];
        [self addChild:b z:1];

        [unarchiver finishDecoding];

        [blobData release];
        [curBlobDirectory release];
        [unarchiver release];
    }
    NSLog(@"%i blobs successfully loaded!", [blobs count]);
}

-(void) SaveBlobs
{
    [[NSUserDefaults standardUserDefaults]setValue:[NSNumber numberWithBool:true] forKey:gameSavedPrev];

    int i = 0;
    for(Blob *b in blobs)
    {
        NSLog(@"Saving Blob #%i...", i);

        NSString *curBlobDirectory = [[NSString alloc]initWithFormat:@"%@%i", saveDirectoryBlobs, i];

        NSMutableData *blobData = [[NSMutableData alloc]init];
        NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData:blobData];

        [archiver encodeInt:b.position.x forKey:@"x"];
        [archiver encodeInt:b.position.y forKey:@"y"];
        [archiver encodeInt:b.health forKey:@"health"];
        [archiver encodeInt:b.mating forKey:@"mating"];
        [archiver encodeInt:b.aiEntity forKey:@"entity"];
        [archiver encodeInt:b.action forKey:@"action"];
        [archiver encodeInt:b.faction forKey:@"faction"];
        [archiver encodeBool:b.equippedHelmet forKey:@"helmet"];
        [archiver encodeBool:b.equippedSpear forKey:@"spear"];
        [archiver encodeInt:b.position.x forKey:@"gx"];
        [archiver encodeInt:b.position.y forKey:@"gy"];
        [archiver encodeInt:b.homeID forKey:@"home"];
        [archiver encodeInt:b.aiID forKey:@"ai"];
        [archiver encodeInt:b.iD forKey:@"id"];

        [archiver finishEncoding];

        BOOL success = [blobData writeToFile:curBlobDirectory atomically:YES];
        NSLog(@"Blob directory is: %@", curBlobDirectory);

        [archiver release];
        [blobData release];
        [curBlobDirectory release];

        i++;
    }
}
  • 1 1 Answer
  • 0 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-27T03:35:55+00:00Added an answer on May 27, 2026 at 3:35 am

    replace everything that is like

    b.health = [[unarchiver decodeObjectForKey:@"health"]intValue];
    

    with

    b.health = [unarchiver decodeIntForKey:@"health"];
    

    If you use encodeInt:forKey: you have to use decodeIntForKey:.
    If you use encodeBool:forKey: you have to usedecodeBoolForKey:`.

    and so on

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to render a haml file in a javascript response like so:
Basically, what I'm trying to create is a page of div tags, each has

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.