NSMutableArray has a way to do this, if you know exactly where to save it:
//Writing to file if(![array writeToFile:path atomically:NO]) { NSLog(@"Array wasn't saved properly"); }; //Reading from File NSArray *array; array = [NSArray arrayWithContentsOfFile:path]; if(!array) { array = [[NSMutableArray alloc] init]; } else { array = [[NSMutableArray alloc] initWithArray:array]; };
Or you can use NSUserDefaults:
//Saving it [[NSUserDefaults standardUserDefaults] setObject:array forKey:@"My Key"]; //Loading it NSArray *array; array = [[NSUserDefaults standardUserDefaults] objectForKey:@"My Key"]; if(!array) { array = [[NSMutableArray alloc] init]; } else { array = [[NSMutableArray alloc] initWithArray:array]; };
source share