Updating & changing settings plist files with new versions of an app


/ Published in: Objective C
Save to your folder(s)

This code works


Copy this code and paste it in your HTML
  1. - (void)readSettings {
  2.  
  3. // Get Paths
  4. NSString *defaultSettingsPath = [[NSBundle mainBundle] pathForResource:@"DefaultSettings" ofType:@"plist"];
  5. NSString *settingsPath = [self.applicationDocumentsPath stringByAppendingPathComponent:@"Settings.plist"];
  6.  
  7. // Read in Default settings
  8. self.settings = [NSMutableDictionary dictionaryWithContentsOfFile:defaultSettingsPath];
  9.  
  10. // Read in Current settings and merge
  11. NSDictionary *currentSettings = [NSDictionary dictionaryWithContentsOfFile:settingsPath];
  12. for (NSString *key in [currentSettings allKeys]) {
  13. if ([[self.settings allKeys] indexOfObject:key] != NSNotFound) {
  14. if (![[currentSettings objectForKey:key] isEqual:[self.settings objectForKey:key]]) {
  15.  
  16. // Different so merge
  17. [self.settings setObject:[currentSettings objectForKey:key] forKey:key];
  18.  
  19. }
  20. }
  21. }
  22.  
  23. }
  24.  
  25. - (void)saveSettings {
  26. if (self.settings) {
  27. NSString *settingsPath = [self.applicationDocumentsPath stringByAppendingPathComponent:@"Settings.plist"];
  28. [self.settings writeToFile:settingsPath atomically:YES];
  29. }
  30. }

URL: http://stackoverflow.com/questions/1609305/updating-changing-settings-plist-files-with-new-versions-of-an-app

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.