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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:06:29+00:00 2026-06-06T03:06:29+00:00

I have an object that I convert into NSData using an NSKeyedArchiver and then

  • 0

I have an object that I convert into NSData using an NSKeyedArchiver and then store it into NSUserDefaults. Everything gets saved correctly except for the elements of an array that the object has. All the objects in the array have conform to the NSCoder protocols (or whatever theyre called- ex. self.property = [decoder decodeObjectForKey:@"key"] and [encoder encodeObjectForKey:@"key"])

When I save the object, the elements of the array remain in the array, but their properties themselves do not get saved. i DO call the sycnrhonize method, so that is not the issue.

NOTE that all other times i save & load it is correct, it just does not save the elements of an array that belongs to an object. Do i have to save that separately?

The "current status" NSNumber is not being saved. Objective and target are being saved

import "Level.h"

@implementation Level
@synthesize objective = _objective;
@synthesize isComplete = _isComplete;
@synthesize goldReward = _goldReward;
@synthesize xpReward = _xpReward;
@synthesize missionID = _missionID;
@synthesize currentStatus = _currentStatus;
@synthesize targetName = _targetName;
@synthesize owner = _owner;

-(void)dealloc{

[super dealloc];
  }

-(id)initWithMissionID:(int)number{

if (self = [super init]) {
    self.currentStatus = 0;
    self.isComplete = NO;
    self.missionID = [NSNumber numberWithInt:number];
    [self setUpMisson];
}
return self;
}
-(void)setUpMisson{
if ([self.missionID intValue] == 0) {
    self.xpReward = [NSNumber numberWithInt:100];
    self.goldReward = [NSNumber numberWithInt:100];
    self.objective = [NSNumber numberWithInt:3];
    self.targetName = @"Swordsman";
    CCLOG(@"Gotta kill some swordsmen!");
}
}
-(void)encodeWithCoder:(NSCoder *)encoder{
[encoder encodeObject:self.objective forKey:@"objective"];
[encoder encodeObject:self.isComplete forKey:@"isComplete"];
[encoder encodeObject:self.goldReward forKey:@"goldReward"];
[encoder encodeObject:self.xpReward forKey:@"xpReward"];
[encoder encodeObject:self.missionID forKey:@"missionID"];
[encoder encodeObject:self.currentStatus forKey:@"currentStatus"];
[encoder encodeObject:self.targetName forKey:@"targetName"];
[encoder encodeObject:self.owner forKey:@"owner"];
CCLOG(@"SAVING LEVEL");
}
-(id)initWithCoder:(NSCoder *)decoder{
if (self = [super init]) {
    self.objective = [[decoder decodeObjectForKey:@"objective"]retain];
    self.isComplete = [[decoder decodeObjectForKey:@"isComplete"]retain];
    self.goldReward = [[decoder decodeObjectForKey:@"goldReward"]retain];
    self.xpReward = [[decoder decodeObjectForKey:@"xpReward"]retain];
    self.missionID = [[decoder decodeObjectForKey:@"missionID"]retain];
    self.targetName = [[decoder decodeObjectForKey:@"targetName"]retain];
    self.owner = [[decoder decodeObjectForKey:@"owner"]retain];
    CCLOG(@"LOADING LEVEL");
}
return self;
}
-(void)updateStatusForKill:(AI *)killedTarget{
CCLOG(@"WE KILLED: %@ and OUR GOAL IS: %@",killedTarget.name,self.targetName);

if ([killedTarget.name isEqualToString:self.targetName]) {
    [self setCurrentStatus:[NSNumber numberWithInt:[self.currentStatus intValue]+1]];
    CCLOG(@"Current Status: %i Objective: %i", [self.currentStatus intValue],[self.objective intValue]);
    if ([self.currentStatus intValue] == [self.objective intValue]) {
        [self completeMission];
    }
}
}
-(void)completeMission{
[self.owner setCoins:[NSNumber numberWithInt:[[self.owner coins]intValue] + [self.goldReward intValue]]];
[self.owner setXp:[NSNumber numberWithInt:[[self.owner xp]intValue] + [self.xpReward intValue]]];
CCLOG(@"complete");
[[self.owner missionList]removeObject:self];

}
@end

EDIT: The "owner" refers back to the object being saved. I think this is where the problem is, so I’m removing that and testing again.

EDIT: and that did nothing!

  • 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-06-06T03:06:31+00:00Added an answer on June 6, 2026 at 3:06 am

    found a workaround using a Unique-Id system for each mission and saving the progress for each mission separately into NSUserDefaults which are just then loaded again. Not ideal, but it works. Thanks for everyone’s help!

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

Sidebar

Related Questions

I have an xml document object that I need to convert into a string.
I'm using an XMLparser class to convert XML into an object. The problem is
I have a collection of domain objects that I need to convert into another
I have an NSData abject called objNSData, and I can convert a string into
I'm using ruby-opencv to do some image processing. I have an IplImage object that
I have converted a PNG into a bitmap, then converted that into bitmapData. I
I have set up a object class that I am using to create my
I have a web service call that returns XML which I convert into domain
I created Java object and I used JAXB to convert that object into XML.
I have a List of objects that I would like to convert to a

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.