views:

127

answers:

2

Has anyone written iPhone classes that mimic the behavior of the Application Settings? It would be nice to be able to define settings tables for use within my app using exactly the same XML structure, etc.

+1  A: 

The application settings (or NSUserDefaults) is essentially a glorified NSDictionary. You add objects to the settings and associate them with keys, so you can retrieve them later on.

If you want to do this, just create a class which wraps a singleton instance of a NSDictionary. That way you could reference it throughout your app like:

[[MyAppSettings sharedInstance] objectForKey:key];
CJ
By the way, if you want to save/restore the dictionary between app sessions, use - (id)initWithContentsOfFile:(NSString *)path, and - (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag in order to convert back and forth from plist files.
CJ
+4  A: 

See http://stackoverflow.com/questions/1043172/is-there-a-library-or-framework-for-setting-preferences-from-within-an-iphone-app

Esp. the mySettings library mentioned there:

mySettings [...] uses a plist configuration file like the one used by the settings app, with some added options.

[...]

By default the settings themselves are stored in the standard user defaults object ([NSUserDefaults standardUserDefaults]), but you can use any object that supports key-value coding. This enables you to use your model classes directly in the settings view.

oefe
Great, mySettings is (I think) exactly what I'm looking for. Thanks!
Greg Maletic