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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:32:14+00:00 2026-06-06T10:32:14+00:00

Good evening everyone, I was hoping you could help with an Objective-C question I

  • 0

Good evening everyone, I was hoping you could help with an Objective-C question I have.

In my app, I have a mutable array that contains 16 objects; the objects being images.

I would like to save and load the array so that the images are retained when the user quits the program.

I am new to data persistence and I can see there are several ways of saving and loading data and I am familiar with the NSUserDefaults method of saving and loading data. I am aware though that you cannot save arrays with images in this way.

Could someone please explain, perhaps with an example of the best and simplest way of saving and loading an array with images? Any help would be great as I’m unsure the best way to go with this.

Thanks everyone in advance!

  • 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-06T10:32:15+00:00Added an answer on June 6, 2026 at 10:32 am

    Consider using NSKeyedArchiver.

    // Archive
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:theArray];
    NSString *path = @"/Users/Anne/Desktop/archive.dat";
    [data writeToFile:path options:NSDataWritingAtomic error:nil];
    
    // Unarchive
    NSString *path = @"/Users/Anne/Desktop/archive.dat";
    NSMutableArray *theArray = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
    

    This way you can be sure the unarchived array is identical to the original.
    All classes conforming to the NSCoding protocol can be used by NSKeyedArchiver.

    Note: You can use any extension.

    Response to comment:

    The following should work on iOS:

    // The Array
    NSMutableArray * array = [[NSMutableArray alloc] init]; 
    
    // Determine Path
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path = [ [paths objectAtIndex:0] stringByAppendingPathComponent:@"archive.dat"];
    
    // Archive Array
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:array];
    [data writeToFile:path options:NSDataWritingAtomic error:nil];
    
    // Unarchive Array
    NSMutableArray *theArray = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good evening, In my app that I'm currently developing, I have a class that
Good evening everyone, I have a quick question on a homework assignment my class
Good evening everyone. I am puzzling over the oddity that the jQuery Marquee plugin
Good evening, i need to know how can i have one .h file that
Good evening I have a JTable that I built with a TableModel how to
Good evening everyone. I am currently using MVC 3 and I have a viewmodel
Good evening fellow stackers, I have a mutex and threaded related question about //
Good morning\evening everyone! i have a string in a format like 0x0SD30SV8GN48N84GN wich represent
Good Evening All, I have a textbox that needs to accept 14 digits plus
Good evening. Can You help me please with some batch file? I have an

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.