In my application, I have some color settings, font settings and a Dictionary containing application specific objects ( these objects are classes with properties, which are private to application ). The color settings and font settings are sort of public settings for the application. I would like to save them to NSUserDefaults but it will show any of the font or color properly, so I am saving them using this line of code
// reading the value
NSData *foregroundcolorData = [[NSUserDefaults standardUserDefaults] objectForKey:@"foregroundcolor"];
UIColor *foregndcolor = [NSKeyedUnarchiver unarchiveObjectWithData:foregroundcolorData];
// setting the default values
NSData *foregndcolorData = [NSKeyedArchiver archivedDataWithRootObject:[UIColor blackColor]];
[[NSUserDefaults standardUserDefaults] setObject:foregndcolorData forKey:@"foregroundcolor"];
// saving the changes, by putting everything in a dictionary called "preferences"
[[NSUserDefaults standardUserDefaults] registerDefaults:preferences];
[[NSUserDefaults standardUserDefaults] synchronize];
I decided to put every settings in the application UI. In order for the code above to work, I need to add a “settings bundle” file to the application project. This causes the application to put an entry in the device/system settings panel. It is empty, Since I don’t set any application configuration details in the settings bundle file.
How can I get around this problem ?
Custom holder object