Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Store your preferences in an NSDictionary or NSMutableDictionary, and set up an IBAction on your button that looks something like

Code:
- (IBAction)clearPreferences:(id)sender {
	[preferences enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
		/* The code that actually clears each preference... you might want
 		to do something different for each preference based on its data type...
 		like, set NSStrings to @"", and NSNumbers to 0...
 		it depends on what "clear" is in your app.
 		For example:*/

 		if ([obj isMemberOfClass:[NSString class]]) obj = @"";
	}
}

Hope that helps.

Sorry for the misunderstand... your post only said "Is it possible?", I didn't realize that in the title you'd actually asked for an example.
 
Store your preferences in an NSDictionary or NSMutableDictionary, and set up an IBAction on your button that looks something like

Code:
- (IBAction)clearPreferences:(id)sender {
	[preferences enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
		/* The code that actually clears each preference... you might want
 		to do something different for each preference based on its data type...
 		like, set NSStrings to @"", and NSNumbers to 0...
 		it depends on what "clear" is in your app.
 		For example:*/

 		if ([obj isMemberOfClass:[NSString class]]) obj = @"";
	}
}

Hope that helps.

Sorry for the misunderstand... your post only said "Is it possible?", I didn't realize that in the title you'd actually asked for an example.

That's ok. I also noticed that I just put the right question on the topic but not in the content.

Thanks for your example. It is a bit different to my case. I am writing a reader app and some preferences are based on the book names. So these preferences are not fixed and I cannot know what they are when I am writing the code.

But your example reminds me that I can save all preference key names in a unique & global one and rebuild the dictionary from it when I need to delete them.

It's not very convenient. So really curious if there is an easier - just one function call - to do all of these. Like on Windows, if I save the preference in a file or registry, just need to delete the file or the whole reg key. That's it.
 
NSUserDefaults supports dictionary values. You could store your per-book preferences in a dictionary, then store that dictionary using NSUserDefaults with a key unique to the book. You can jettison that book's preferences by using removeObjectForKey: to remove the dictionary.
 
NSUserDefaults supports dictionary values. You could store your per-book preferences in a dictionary, then store that dictionary using NSUserDefaults with a key unique to the book. You can jettison that book's preferences by using removeObjectForKey: to remove the dictionary.

That's a good idea. Thanks:)
 
Finally found this: CFPreferencesCopyKeyList. I now can use it to get all preference keys and delete them one by one :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.