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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:50:50+00:00 2026-06-10T02:50:50+00:00

I am reading and writing an array to NSuserdefults in this way: indexDelete =

  • 0

I am reading and writing an array to NSuserdefults in this way:

indexDelete = button.tag;

                    NSUserDefaults *currentDefaults = [NSUserDefaults standardUserDefaults];
                    NSData *dataRepresentingSavedArray = [currentDefaults objectForKey:@"save"];
                    if (dataRepresentingSavedArray != nil)
                    {
                        NSArray *oldSavedArray = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingSavedArray];
                        if (oldSavedArray != nil)
                            myIntegers = [[NSMutableArray alloc] initWithArray:oldSavedArray];
                        else
                            myIntegers = [[NSMutableArray alloc] init];
                    }

                    [myIntegers addObject:[NSNumber numberWithInteger:indexDelete]];

                    NSLog (@"Array myIntegers: %@", myIntegers);

                    [[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:myIntegers] forKey:@"save"];

Every thing works fine if I keep the line:

myIntegers = [[NSMutableArray alloc] init];

out of the brackets, because even if the data is there, it is not written or read correctly:

I get this error: -[NSKeyedUnarchiver initForReadingWithData:]: data is NULL

What im I doing wrong??

  • 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-10T02:50:52+00:00Added an answer on June 10, 2026 at 2:50 am

    You never initialize your myIntegers. The first time you get the object for key save from your defaults you get a nil object (hence not entering the if closure and allocating the structure). After that you try to archive a nil object, which is probably the cause for the error you’re getting.

    Try moving the initialization of the array before this and only adding the objects from the previous saving if they exist:

    myIntegers = [[NSMutableArray alloc] init];
    NSUserDefaults *currentDefaults = [NSUserDefaults standardUserDefaults];
    NSData *dataRepresentingSavedArray = [currentDefaults objectForKey:@"save"];
    if (dataRepresentingSavedArray != nil)
    {
        NSArray *oldSavedArray = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingSavedArray];
        if (oldSavedArray != nil)
            [myIntegers addObjectsFromArray:oldSavedArray];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I copy and paste code from this URL for creating and reading/writing a proc
I am having difficulties w/ writing and reading an array of objects from a
I have a 2d Array of memory. I have multiple threads reading and writing
While implementing XML file reading/writing in my application I saw that when I call
I want to know the files a given process is reading/writing. Is there a
I am little confused... Is it true that reading\writing from several threads all except
I'm developing an app that starts a System.Threading.Timer which does some fairly rapid reading/writing
Possible Duplicate: Reading and writing images to an SQLite DB for iPhone use How
I am writing a kernel module and it is about reading and writing MSRs.
My application is SL2 reading and writing data through an Entity Framework Model exposed

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.