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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:12:35+00:00 2026-06-16T13:12:35+00:00

I have an iOS app that stores two NSMutableArray ‘s as objects in NSUserDefaults

  • 0

I have an iOS app that stores two NSMutableArray‘s as objects in NSUserDefaults in the event that there is no WiFi or Data connectivity. On a subsequent visit, the user should be able to load the stored data in their table by retrieving the saved data from NSUserDefaults, but unfortunately I am unable to do so. The NSMutableArrays are storing objects that hold various NSString values as parameters.

Here is the code that saves my data in my Singleton class:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[DataModel sharedInstance].testResultList forKey:@"resultTable"];
    [defaults setObject:[DataModel sharedInstance].testResults forKey:@"jsonTable"];
    [defaults synchronize];

and here is the code from UITableView class which is supposed to retrieve the data and load them into a table:

- (void)viewDidLoad
{
    [super viewDidLoad];


    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    if ([[DataModel sharedInstance].testResults count] == 0) {

        if ([defaults objectForKey:@"resultTable"] == nil) {

            return;
        }

        else {

            [DataModel sharedInstance].testResultList = [defaults objectForKey:@"resultTable"];
            [DataModel sharedInstance].testResults = [defaults objectForKey:@"jsonTable"];


        }


    }


}

and here is my cellForRowAtIndexPath() method:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"testresultcell";
    ResultTableViewCell *cell = (ResultTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[ResultTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    TestResult *tResult = [[DataModel sharedInstance].testResultList objectAtIndex:indexPath.row];
    cell.name.text = tResult.testTitle;
    cell.date.text = tResult.dateStamp;
    cell.score.text = [[DataModel sharedInstance] getScore:tResult.score];
    cell.imgView.image = [UIImage imageNamed:[[DataModel sharedInstance] getImg:tResult.score]];

    return cell;
}

Can anyone see what I am doing wrong? I am initially checking to see if the current value of the NSMutableArray‘s are empty. It is only then do I go and check to see if a saved copy of the NSMutableArray exists. If so, then I need to load the array and display the contents in my table.

  • 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-16T13:12:36+00:00Added an answer on June 16, 2026 at 1:12 pm

    The typical pattern for doing that is as follows (I usually do it in my ApplicationDelegate):

    // Set up some default values
    NSDictionary *myDefaults = @{@"aStringDefaultKey":@"someString",@"aBoolKey":@YES};
    
    // Register the default values
    [[NSUserDefaults standardUserDefaults] registerDefaults:myDefaults];
    
    // Get a reference to them
    NSUserDefaults *userSettings = [NSUserDefaults standardUserDefaults];
    

    I don’t see where you registered your default values with NSUserDefaults. If you don’t do that they will not be supplied as default values in the absence of a previously set value.

    Then later you can reference the value or set the value using something like:

    // Set a value or update a value
    [userSettings setObject:@"anotherString" forKey:@"aStringDefaultKey"];
    [userSettings objectForKey:@"aStringDefaultKey"];
    

    EDIT: And if it turns out that your DataModel Object (which you didn’t post any code for) cannot be stored because it does not conform to NSCopy rules, then serialize it into an NSData Object which CAN be stored in an NSDictionary, and do it that way.

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

Sidebar

Related Questions

I have an iOS app that stores some data in a sqlite database. The
I have an iOS app that pulls user data down from a web service
I have an iPhone app out that stores data on the device. I want
I have an iOS app that uses a SQLite DB to store its data
I have an iOS app that uses Core Data for persistent data storage. I
I have developed a small app that stores locally in iOS through archiving an
I have been working on a Core Data iOS app that works perfectly through
I have an iOS app that uses a number of enums for valid values,
I have an old iOS app that I never distributed and am now trying
I have a Rails app that has 2 clients -- an iOS app reads/writes

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.