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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:24:00+00:00 2026-05-16T23:24:00+00:00

[[NSUserDefaults standardUserDefaults] setObject:myArray forKey:@myArray]; If I make an array of custom objects conform to

  • 0
[[NSUserDefaults standardUserDefaults] setObject:myArray forKey:@"myArray"];

If I make an array of custom objects conform to the NSCoding protocol, then does the above work? Do I have to make both the custom class and the view controller that holds the array of custom objects conform to the NSCoding protocol or just the custom class? Do I have to use NSKeyedArchiver somewhere?

  • 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-16T23:24:01+00:00Added an answer on May 16, 2026 at 11:24 pm

    It looks like you will need to archive your array, either with NSKeyedArchiver or NSArchiver. If you first archive the array into a NSData object:

    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:myArray];
    

    You can then store that data in NSUserDefaults like so:

    [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"myArray"];
    

    To load the array, use:

    NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"myArray"];
    NSArray *myArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    

    If you want to use an NSMutableArray then just replace any NSArray occurrences in the code above with NSMutableArray. OR you can just NSMutableArray *myMutableArray = [myArray mutableCopy] will give you a NSMutableArray to work with.

    But then hey, if you are going to the trouble of making it NSCoding compliant, why not just archive it to a file?

    The documentation that made me think that you will need to use an archiver is here so that you can check for yourself.

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

Sidebar

Related Questions

[[NSUserDefaults standardUserDefaults] setObject:myArray forKey:@myArray]; I'm trying to figure out how to save and load
Let's say I saved data to disk like this: [[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:theArray] forKey:@savedArray];
There's a NSUserDefault with Value: [[NSUserDefaults standardUserDefaults] setObject:@1 forKey:@aValue]; Can it be overwritten by
I use these methods [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@ar] forKey:@AppleLanguages]; [[NSUserDefaults standardUserDefaults] synchronize]; to force
Is the name of localized jp or jap in [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@jp or
This is my code NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if ([defaults objectForKey:@FBAccessTokenKey] && [defaults
Is there a difference in speed between the following two cases: A: userName=[[NSUserDefaults standardUserDefaults]
i`m trying to make an NSMutableArray From NSUserDefaults so i can add/delete and edit
I would like to save an array of view controllers in NSUserDefaults, but I
I have an array that I'm saving to NSUserDefaults, containing an array of my

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.