Hello everyone!
I'm working on cleaning up an app that was written by a colleague of mine a
while ago, and one of the things that he did quite a bit was use "properties"
(declared as @properties, with custom getters/setters) that are actually backed
by NSUserDefaults. Seemingly, this was to provide excellent persistence - no
matter how the app closed or crashed, it always remembered exactly what was
going on. This is still important even with the advent of multi-tasking, as I
am still targeting 3.x, as well as users without multi-tasking.
Here's an example of one of his "properties":
- (BOOL)gameShouldBeCounted { return [[NSUserDefaults standardUserDefaults]
boolForKey:@"gameShouldBeCounted"]; }
- (void)setGameShouldBeCounted:(BOOL)shouldBeCounted {
[[NSUserDefaults standardUserDefaults] setBool:shouldBeCounted
forKey:@"gameShouldBeCounted"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
Calling synchronize that often can't possibly be efficient, but it seems to be
the only way to make sure that defaults actually get written right away. Does
anyone have any recommendations of how to make this better? I was thinking
about some sort of KVC/O system, where actual ivars were used and
NSUserDefaultsController was set to observe them and update asynchronously, but
I have no idea where to start with a system like that.
Any advice is welcome!
Sincerely,
Carter Allen_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]