/ Published in: Objective C
Some macros that I use in many applications, provides an easy way to observe/retrieve preferences and access common application information
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#define APP_NAME [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"] #define APP_VERSION [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"] #define OPEN_URL(urlString) [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlString]] // Retrieving preference values #define PREF_KEY_VALUE(x) [[[NSUserDefaultsController sharedUserDefaultsController] values] valueForKey:(x)] #define PREF_KEY_BOOL(x) [(PREF_KEY_VALUE(x)) boolValue] #define PREF_SET_KEY_VALUE(x, y) [[[NSUserDefaultsController sharedUserDefaultsController] values] setValue:(y) forKey:(x)] #define PREF_OBSERVE_VALUE(x, y) [[NSUserDefaultsController sharedUserDefaultsController] addObserver:y forKeyPath:x options:NSKeyValueObservingOptionOld context:nil]; /* key, observer, object */ #define OB_OBSERVE_VALUE(x, y, z) [(z) addObserver:y forKeyPath:x options:NSKeyValueObservingOptionOld context:nil]; #ifdef __OBJC__ static inline BOOL isEmpty(id thing) { return thing == nil || ([thing respondsToSelector:@selector(length)] || ([thing respondsToSelector:@selector(count)] } #endif
URL: http://mabblog.com/source.html