Skip to content

Instantly share code, notes, and snippets.

@matej
Created July 23, 2010 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matej/487276 to your computer and use it in GitHub Desktop.
Save matej/487276 to your computer and use it in GitHub Desktop.
#define GCSynthesizeUserDefaultsGetter(cls, key, instance, name) \
- (cls *)name { \
if (!instance) { \
id o = [[NSUserDefaults standardUserDefaults] objectForKey:(key)]; \
if (![o isKindOfClass:[cls class]]) o = nil; \
\
[o retain]; \
[instance release]; \
instance = o; \
} \
\
return instance; \
}
#define GCSSynthesizeUserDefaultsSetter(cls, key, instance, setterName) \
- (void)setterName(cls*)o { \
[o retain]; \
[instance release]; \
instance = o; \
\
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; \
[prefs setObject:instance forKey:(key)]; \
[prefs synchronize]; \
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment