How to store a NSArray into plist or database?
ios, iphone, xcode
Solution
Easies way is to save it to a 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];
Loading it later like this:
//Load it
NSMutableArray *arr = [[NSMutableArray alloc] initWithContentsOfFile:path];
Problem
I have this app which has to store information when I hit some button.. The fact is, when I hit this button I need to store this data locally so I can take this in other view which is going to load it at show it as data. I'm thinking in some plis or database. The problem is I can't get to an idea or something good. - I pass the array with objects. - I have the button. Which is the best way to store the entire array inside the phone, so I can read it as the same way it is stored? If this is not clear, please tell me. Thanks in advance