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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:49:42+00:00 2026-05-29T03:49:42+00:00

I cant get the archivedDataWithRootObject method to call encodeWithCoder, it seems pretty simple from

  • 0

I cant get the archivedDataWithRootObject method to call encodeWithCoder, it seems pretty simple from what I understand but it doesn’t work.
Here’s the code:

#import <Foundation/Foundation.h>

@interface Details : NSObject <NSCoding>{

NSMutableArray *myArray;
}

@property(nonatomic,retain) NSMutableArray *myArray;

@end

#import "Details.h"

@implementation Details
@synthesize myArray;


-(id)init{
 [super init];
 return self;
}

-(id)initWithCoder:(NSCoder *)aDecoder{

NSLog(@"initWithCoder");
if (self = [super init])
{
    self.myArray = [[aDecoder decodeObjectForKey:@"details"]retain];

} 
return self;
}

- (NSMutableArray*)getDetails{

NSLog(@"getDetials");
// NSUserDefaults *currentDefaults = [NSUserDefaults standardUserDefaults];
NSData *details = [[NSUserDefaults standardUserDefaults] objectForKey:@"details"];
if (details != nil){ 
  NSArray *oldSavedArray = [NSKeyedUnarchiver unarchiveObjectWithData:details];
    if (oldSavedArray != nil)
        self.myArray = [[NSMutableArray alloc] initWithArray:oldSavedArray];
    else
        self.myArray = [[NSMutableArray alloc] initWithCapacity:1];
 }
 return self.myArray;
}

- (void) addDetails:(NSMutableArray *)details{

      NSLog(@"add Details");

     [self.myArray addObject:details]; 
     [NSKeyedArchiver archivedDataWithRootObject:self.myArray];
  }

- (void) encodeWithCoder:(NSCoder *)coder;
{
  NSLog(@"encodeWithCoder");
  [coder encodeObject:self.myArray forKey:@"details"];
} 

@end

NSLog(@”encodeWithCoder”) doesn’t run.
I might be missing something, If anyone has any ideas it would be appreciated.

  • 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-29T03:49:43+00:00Added an answer on May 29, 2026 at 3:49 am
    [NSKeyedArchiver archivedDataWithRootObject:self.myArray];
    

    You are telling the NSKeyedArchiver to archive the myArray variable, not the object you have just implemented <NSCoding> with!

    Also that method returns NSData * which you then have to write to disk separately if needed.

    Try this:

    NSData * archivedData = [NSKeyedArchiver archivedDataWithRootObject:self];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Pretty simple but I cant get the exact syntax working. I just want a
I was looking at the answers from different questions here but cant get to
I'm probably doing something realy stupid but I cant get this to work: var
I cant get this to work. I'm trying to match A and B from
Searched and searched for some guidance but cant seem to get anything to work.
I have a code but cant get it to work. I have a .vb
I think this is a simple problem, but i just cant get my head
I cant get this to work anymore Here is my code: ImageView jpgView =
with $element->children() i cant get all the child elements of current element. but how
I have read other related question but i cant really get them to relate

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.