How to save NSArray to plist or database?

I have this application which should store information when I click the button. The thing is, when I click this button, I need to store this data locally, so I can take it in another view that will load it on to show it as data.

I think in some kind of plis or database. The problem is that I cannot understand the idea or something good.

  • I am passing an array with objects.
  • I have a button.

What is the best way to store the entire array inside the phone, so I can read it the same way it is stored?

If this is not clear, tell me.

Thanks in advance

+4
source share
1 answer

Easy way is to save it in plist

Like this:

//create array NSMutableArray *arr = [[NSMutableArray alloc] init]; //Add data [arr addObject:@"some object"]; //String Path of file NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; //Save [arr writeToFile:path atomically:YES]; 

Download later:

 //Load it NSMutableArray *arr = [[NSMutableArray alloc] initWithContentsOfFile:path]; 
+7
source

Source: https://habr.com/ru/post/1415945/


All Articles