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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:40:18+00:00 2026-06-04T08:40:18+00:00

So I got an exception while trying to implement NSKeyedUnarchiver because I’m trying to

  • 0

So I got an exception while trying to implement NSKeyedUnarchiver because I’m trying to save an array of custom objects with NSUsersDefaults. Because I kept on getting an error saying that I had non-properties in it I decided to archive them into NSData. Now I’m getting this error: “incomprehensible archive”.

Here is how I am archiving (I’ve tested all objects to be null, non of them are):

NSMutableArray *array = [[NSMutableArray alloc] initWithArray:anotherArray];
for (int i = 0; i < array.count; i++) {
    CustomObj *obj = [array objectAtIndex:i];
    NSData *newdata  = [NSKeyedArchiver archivedDataWithRootObject:obj];
    [array replaceObjectAtIndex:i withObject:newdata];
}
NSArray *newArray = [[NSArray alloc] initWithArray:array];
[coder setObject:newArray forKey:@"key"];

Here is how I am unarchiving(again everything is tested for null):

if (!arrayM) { arrayM = [[NSMutableArray alloc] init]; NSLog(@"initialized"); }
else {
    for (int i = 0; i < arrayM.count; i++) {
        NSData *data = [arrayM objectAtIndex:i];
        --> The exception happens here: CustomObj *obj  = [NSKeyedUnarchiver unarchiveObjectWithData:data];
        [arrayM replaceObjectAtIndex:i withObject:obj];
    }
}
  • 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-04T08:40:20+00:00Added an answer on June 4, 2026 at 8:40 am

    You didn’t archive it with NSKeyedArchiver, so why would you expect that you would be able to use NSKeyedUnarchiver to get the data back? The way you want to do it is like this. Make your custom object conform to the NSCoding protocol, and implement its two methods (encode and decode). Then you can archive with NSKeyedArchiver on your array of custom objects. The NSKeyedArchiver will call encodeWithCoder on each object, and any objects it contains (if it is a collection).

    EDIT: Call NSKeyedArchiver on the array, not each object. Then when you unarchive it, unarchive it into an array again.

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

Sidebar

Related Questions

I am getting this exception while trying to generate a .PDF file from my
I've got the following exception while trying to open the URL http://localhost:8080/app/clientes/agregar : javax.servlet.ServletException:
I got a strange exception when trying to find out if a property in
I've got the following error: TemplateSyntaxError at /admin/results_cop/copsegmentresult/ Caught an exception while rendering: ('ascii',
I got this error messages while I am trying to deploy my django app
I got this error while trying to compile the below code. I would like
Got these error while trying to run my first Java webservice tutorial in Eclipse.
The below is the runtime exeception which i got while am trying to upload
I'm trying to implement a linked list class in C++ and I got problem.
Got the following exception Failed obtaining configuration for Common.Logging from configuration section 'common/logging'. while

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.