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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:30:34+00:00 2026-06-16T19:30:34+00:00

I have several files to be saved in the Documents folder, this list of

  • 0

I have several files to be saved in the Documents folder, this list of files put in a mutable array. The files must remain in the memory of the iPhone application also closed. The first file is saved, but when I change view controllers and then go back the mutable array becomes empty. How do I keep the data in memory in the Documents folder?

in DetailExpViewController.h

  //....
  @property (nonatomic, strong)NSMutableArray *arrayFavorites;
  @property (nonatomic, assign)BOOL existsArray;
  //....
  @end

in DetailExpViewController.m

- (void)viewDidLoad
 {
      //.....
      if (!self.existsArray){
          /*when I load the view controller this array is always nil even 
            has already  been created*/

           self.arrayFavorites =[[NSMutableArray alloc]init];
     }else{
          NSLog(@"The array exists");
      }
      //....
 }

 -(void) addFavorites:(id)sender{

     //.....
   NSArray *paths = NSSearchPathForDirectoriesInDomains
  (NSDocumentDirectory, NSUserDomainMask, YES);
   NSString *documentsDirectory = [paths objectAtIndex:0];

   NSString * text= [NSString stringWithFormat:@"%@.txt",self.name];
   NSString * documentsPath = [documentsDirectory stringByAppendingPathComponent: text];

   [self.arrayFavorites addObject:text];
   [self.arrayFavorites writeToFile:documentsPath atomically:YES];
   self.existsArray=YES;

   for (id obj in self.arrayFavorites) {

    NSLog(@"%@", self.arrayFavorites);
    //only writes the file at the time, then it is deleted

  }

}

  • 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-16T19:30:35+00:00Added an answer on June 16, 2026 at 7:30 pm

    U can save NSArray in Document Directory like this.

    Note : saving and retrieving filename remains same.

    Its also easy retrieve saved array from doc dir.

    EDIT : If data is complex and large better use SQLITE.


    EDIT : In view Controller's Add to favourite button click event:

     //check favourite saved in doc dir
     if(!saved) //not saved
       //NSMutableArray has not data first time
       //[NSMutableArray addObject:newFavourite];
       //save new data in doc dir
     else // saved
       //firstly retrieve data from doc dir as NSMutableArray
       //[NSMutableArray addObject:newFavourite];
       //Now save again NSMutableArray in doc dir.
    

    By following these instruction files remain permanently in the Documents folder.

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

Sidebar

Related Questions

I have several xml files that are formated this way: <ROOT> <OBJECT> <identity> <id>123</id>
I'm having this issue on several server environments. We have a list at the
I have saved all my files using something like this NSString *fileName = [NSString
I have saved several layout files with the designer but tried to look at
I have several different input files, saved with case numbers .1, .2, etc to
I´m new in iPhone development and I have this memory leak. I´m using an
I have faced this problem several times that whenever we serve files from Blobstore
I have several files and I only want to take specific columns from it.
I have several files which is causing a compile error, can the following be
I have several xml files with different node structure. I want to extract xml

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.