I have two NSMutableArray
\'s. They consist of images or text.
The arrays are displayed via a UITableView
.
When I kill the app the data within the <
Swift Version:
Save Array in NSUserDefaults:
NSUserDefaults.standardUserDefaults().setObject(selection, forKey: "genderFiltersSelection")
Retrieve Bool Array From NSUserDefaults:
if NSUserDefaults.standardUserDefaults().objectForKey("genderFiltersSelection") != nil{
selection = NSUserDefaults.standardUserDefaults().objectForKey("genderFiltersSelection") as? [Bool] ?? [Bool]()
}
Retrieve String Array From NSUserDefaults:
if NSUserDefaults.standardUserDefaults().objectForKey("genderFiltersSelection") != nil{
selection = NSUserDefaults.standardUserDefaults().objectForKey("genderFiltersSelection") as? [String] ?? [String]()
}
If you need to add strings to the NSMutableArray
in ant specific order, or if you are using the NSMutableArray
for a UITableView
you may want to use this instead:
[NSMutableArray insertObject:string atIndex:0];
Save information of Array in NSUserdefaults
with key.
"MutableArray received from JSON response"
[[NSUserDefaults standardUserDefaults] setObject:statuses forKey:@"arrayListing"];
"Retrieve this information(Array) anywhere in the project with same key"
NSArray *arrayList = [[NSUserDefaults standardUserDefaults] valueForKey:@"arrayListing"];
This helped me in my project and hope, it will help someone.