Return to Snippet

Revision: 23071
at January 29, 2010 11:17 by espinallab


Initial Code
- (void)readSettings {

        // Get Paths
        NSString *defaultSettingsPath = [[NSBundle mainBundle] pathForResource:@"DefaultSettings" ofType:@"plist"];
        NSString *settingsPath = [self.applicationDocumentsPath stringByAppendingPathComponent:@"Settings.plist"];

        // Read in Default settings
        self.settings = [NSMutableDictionary dictionaryWithContentsOfFile:defaultSettingsPath];

        // Read in Current settings and merge
        NSDictionary *currentSettings = [NSDictionary dictionaryWithContentsOfFile:settingsPath];
        for (NSString *key in [currentSettings allKeys]) {
                if ([[self.settings allKeys] indexOfObject:key] != NSNotFound) {
                        if (![[currentSettings objectForKey:key] isEqual:[self.settings objectForKey:key]]) {

                                // Different so merge
                                [self.settings setObject:[currentSettings objectForKey:key] forKey:key];

                        }
                }
        }

}

- (void)saveSettings {
        if (self.settings) {
                NSString *settingsPath = [self.applicationDocumentsPath stringByAppendingPathComponent:@"Settings.plist"];
                [self.settings writeToFile:settingsPath atomically:YES];
        }
}

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

Initial Description
This code works

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

Initial Tags
iphone

Initial Language
Objective C