Yes
...
I feel silly saying just that, but I can't imagine what else to add to it.
- (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 = @"";
}
}
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.
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.