У меня есть NSMutableArray, хранящийся в NSUserDefaults.Изменяемый массив корректно редактируется, и результаты редактирования можно просмотреть с помощью:
NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
Однако, когда я закрываю и перезапускаю приложение, пользовательские настройки по умолчанию возвращаются к своим исходнымform.
Я пытаюсь сохранить состояние, запустив этот метод для принудительной синхронизации:
-(void) saveUserDefaults{
if([[NSUserDefaults standardUserDefaults] synchronize]){
NSLog(@"Defaults saved");
}else{
NSLog(@"Defaults save failed");
}
NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
}
Есть какие-либо идеи, почему это не может быть сохранено?*
Я установил пользовательские массивы по умолчанию, используя этот код при первом запуске приложения:
// Check if first time run
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"isFirstRun"] isEqualToString:@"no"]) {
// Not first run, NSUserDefault arrays are already set
}else {
// First Run of Program
// Mark for future
[[NSUserDefaults standardUserDefaults] setObject:@"no" forKey:@"isFirstRun"];
designerArray = [[NSMutableArray alloc] initWithObjects: @"Alberta Ferretti", @"Alberto Fermani", @"Alejandro Ingelmo", @"Alexander McQueen", @"Alexander Wang", @"Ann Demeulemeester", @"Anne Klein", @"Aquatalia", @"Anya Hindmarch", @"Ash", @"Badgley Mischka Platinum Label", @"Balenciaga ", @"BCBGMAXAZRIA", @"BC Studio", @"Be & D", @"Belle by Sigerson Morrison", @"Bettye Muller ", @"Beverly Feldman", @"Botkier", @"Bourne", @"Bottega Veneta", @"Brian Atwood", @"Burberry", @"Burberry Prorsum", @"Camilla Skovgaard", @"Candela", @"Carlos Falchi", @"Casadei ", @"Chie Mihara", @"Chloe", @"Christian Louboutin", @"Claudio Merazzi", @"Coach", @"Cole Haan", @"Comme des Garcons", @"Costume National", @"Cynthis Vincent", @"Delman ", @"Devi Kroell", @"Derek Lam", @"Diane von Furstenberg", @"Dior", @"Dolce & Gabbana", @"Dolce Vita", @"Donald J Pliner ", @"Donna Karan", @"Elie Tahari ", @"Elizabeth and James", @"Emilio Pucci", @"Emma Hope", @"Eric Javits", @"Fendi", @"Ferragamo ", @"Foley & Corinna", @"Frye ", @"Furla", @"Giuseppe Zanotti", @"Givenchy", @"Gucci", @"Halston Heritage", @"H by Hudson", @"Hobo International", @"House of Harlow 1960", @"Hunter", @"Jack Rogers", @"Jean Paul ", @"Jerome C. Rousseau", @"Jil Sander", @"Jimmy Choo", @"Joan & David", @"Joie", @"Jonathan Kelsey", @"Judith Leiber", @"Juicy Couture", @"Junya Watanabe", @"Kate Spade", @"Kooba", @"Kork-Ease ", @"Kors Michael Kors", @"L.A.M.B.", @"LD Tuttle", @"Le Silla", @"Lanvin", @"Lilly Pulitzer", @"Linea Pelle", @"Lockheart", @"Loeffler Randall", @"Longchamp", @"Luciano Padovan", @"Maison Martin Margiela", @"Maison Martin Margiela MM6", @"MANITOBAH MUKLUKS ", @"MANOLO BLAHNIK ", @"Marc by Marc Jacobs", @"Marc Jacobs", @"Marina Rinaldi", @"MATT BERNSON ", @"Max Kibardin", @"MCM", @"Melissa", @"Michael Kors", @"MICHAEL MICHAEL KORS", @"Milly", @"Miu Miu", @"Miss Sixty", @"Missoni", @"Modern Vintage", @"Moschino", @"Moschino Cheap and Chic", @"Nancy Gonzalez", @"Narcisco Rodriguez", @"Nina Ricci", @"Nicholas Kirkwood", @"Olivia Harris", @"Opening Ceremony", @"Oscar de la Renta", @"PATRICIA GREEN ", @"Pedro Garcia ", @"Philosophy by Alberta Ferretti", @"Pollini", @"Prada", @"Proenza Schouler", @"Pura Lopez",@"Rachel Comey ", @"Rag & Bone", @"Ralph Lauren", @"Rebecca Minkoff", @"Rene Caovilla ", @"Repetto", @"Robert Clergerie ", @"Rock & Republic", @"Rosegold", @"Rupert Sanderson", @"Salvatore Ferragamo", @"SAM EDELMAN ", @"Scorah Pattulo", @"See by Chloe", @"7 for all mankind ", @"Sergio Rossi", @"Sigerson Morrison", @"Stella McCartney ", @"Stephane Verdino", @"Steve Madden", @"Storksak", @"Stuart Weitzman", @"Studio Pollini", @"Taryn Rose", @"Thakoon", @"Theory", @"Tracy Reese", @"Tod's", @"TOMS ", @"Tory Burch", @"UGG Australia", @"Valentino", @"Vera Wang Lavender Label", @"Versace", @"Via Spiga", @"Vince Camuto", @"Yves Saint Laurent", @"Zac Posen", @"Zagliani", @"-", nil];
[[NSUserDefaults standardUserDefaults] setObject:designerArray forKey:@"designerArray"];
shoeStyles = [[NSMutableArray alloc] initWithObjects: @"Ankle Strap", @"Ballet Flat", @"Boot", @"Bootie", @"Buckle Strap", @"Caged", @"Cowboy Boot", @"D'Orsay", @"Espadrille", @"Flat", @"Flat Sandal", @"Lace Up Boot",@"Mary Jane", @"Mid Calf Boot", @"Open Toe Flat", @"Open Toe Pump", @"Platform", @"Strappy Sandal", @"Thigh High Boot", @"Rain Boot", @"Sling Back", @"T-Strap", @"-", nil];
[[NSUserDefaults standardUserDefaults] setObject:shoeStyles forKey:@"shoeStyles"];