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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:15:46+00:00 2026-06-09T13:15:46+00:00

On viewDidLoad , my application populates the NSMutableArray arrayOfHaiku , which is an array

  • 0

On viewDidLoad, my application populates the NSMutableArray arrayOfHaiku, which is an array of NSDictionary items, as follows:

 NSError *error;
 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
 NSString *documentsDirectory = [paths objectAtIndex:0];
 NSString *path = [documentsDirectory stringByAppendingPathComponent:@"haiku.plist"];
 NSFileManager *fileManager = [NSFileManager defaultManager];
 if (![fileManager fileExistsAtPath: path])
 {
 NSString *bundle = [[NSBundle mainBundle] pathForResource:@"haiku" ofType:@"plist"];
 [fileManager copyItemAtPath:bundle toPath: path error:&error];
 }
 self.arrayOfHaiku = [[NSMutableArray alloc] initWithContentsOfFile: path];

While using the application, the user adds items to self.arrayOfHaiku. As of now I include the following code in viewDidUnload:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"haiku.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath: path])
{
    [self.arrayOfHaiku writeToFile:path atomically:YES];
}

Here are my questions:

  1. Does my code for viewDidUnload a) simply write over the document storing the array in the Documents folder (that is, the array accessed in viewDidLoad) with the new, expanded array (which is what I want to do), or does it b) append the new, expanded array to the array already stored in the Documents folder so that I end up with an array that’s more than twice as long with a bunch of repeats?

  2. If the answer is “b)”, what do I need to change to do “a)”?

  3. Is it better a) to do it the way I’m doing it, at viewDidUnload, or b) to expand the array in the documents folder each time the user adds an item to self.arrayOfHaiku?

  4. If the answer is “b)”, what do I need to change to do “b)”?

Thanks for your help.

  • 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-09T13:15:47+00:00Added an answer on June 9, 2026 at 1:15 pm
    1. If the file exists, it will be overwritten, else it will be created (option a).

    2. It all depends on the number of records. If you have a huge number then rewriting them everytime could be expensive. Otherwise you have to look to another solution. I honestly would not suggest using viewDidUnload because it might not fire in certain circumstances for example, if the app is backgrounded.

    3. Unfortunately, there is no ready function for ‘updating’ a plist with dictionary objects like writeToFile: . You can use NSFileHandler’s fileHandleForUpdatingAtPath: function but then you would have to change the plist file manually (Which i dont think is a simple process).

    I personally would suggest using Core Data unless your data structure is very simple and ‘option a’ would not be an expensive process.

    hope this helps.

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

Sidebar

Related Questions

On my viewDidLoad I load from a webservice the first 5 items of an
In my Map application I have called web service method in ViewDidLoad method. Therefore
I'm building an application based on the Utility template from Xcode, to which I
I have a problem with the methoed ViewDidLoad... At the start, my application must
I am creating a application in which I can need to play a video
I am building view based application,which has many pages an in every page ther
I am making an application in which i have put a progress bar .
iam working on one application.In that application,i declared the NSXmlParser object in viewdidload method.But
my application has a UIViewController subclass which is being managed by a UINavigationController. In
I'm writing an iPhone application which you need to authenticate at the beginning. Therefore

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.