- Download the mySettings project:
- Using mercurial: hg clone https://bitbucket.org/karemorstol/mysettings/
- ... or you can use the download links at the top right corner of this page. Extract it to the appropriate folder (from now on referred to as the <mySettings folder>).
- Open the project that will be using mySettings.
- Select "Add to project" from the project menu.
- Locate "mySettings.xcodeproj" in <mySettings folder> and add it (make sure "copy items into destination groups folder" is not checked).
- Find "libmySettings.a" under the newly added "mySettings.xcodeproj" item, and drag it to the "Link Binary with Libraries" phase of the appropriate target.
- Double-click the target, click the plus button under "Direct Dependencies" and select the "mySettings"-library.
- Go to <mySettings folder>/Code/Classes/, and select "SettingsViewController.h" and "SettingsMetadataSource.h".
- Also select SettingsCell.h and/or SettingsCellProtocol.h if you're going to create your own custom table cells.
- Drag the files to your project in Xcode and drop them wherever XCode will let you. Again, make sure "copy items into destination groups folder" isn't checked and click add.
- Create your Root.plist configuration file and place it under "Resources". You can use the file from <mySettings folder>/Resources/ as a starting point.
- Drag the plist file to the "Copy Bundle Resources" - phase of the target.
- And start programming.
To show the settings view controller:
NSString *plist = [[NSBundle mainBundle] pathForResource:@"Root" ofType:@"plist"]; SettingsViewController *settingsviewcontroller = [[SettingsViewController alloc] initWithConfigFile:plist]; [navigationController pushViewController:settingsviewcontroller animated:YES];
Which will retrieve and store the settings in the standard user defaults object ([NSUserDefaults standardUserDefaults]). Or you can use any other object (provided it supports key-value coding):
SettingsViewController *settingsviewcontroller = [[SettingsViewController alloc] initWithConfigFile:plist andSettings:anyobject];