Posted By

iloveitaly on 04/11/07


Tagged

cocoa macros


Versions (?)

Who likes this?

13 people have marked this snippet as a favorite

nesium
rastersize
davidsi
stationstops
avanadra
illogic
dapan
dannolan
sb
bucko
synced
nellynette
cnathan


Useful Cocoa Macros


 / Published in: Objective C
 

URL: http://mabblog.com/source.html

Some macros that I use in many applications, provides an easy way to observe/retrieve preferences and access common application information

  1. #define APP_NAME [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]
  2. #define APP_VERSION [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]
  3. #define OPEN_URL(urlString) [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlString]]
  4.  
  5. // Retrieving preference values
  6. #define PREF_KEY_VALUE(x) [[[NSUserDefaultsController sharedUserDefaultsController] values] valueForKey:(x)]
  7. #define PREF_KEY_BOOL(x) [(PREF_KEY_VALUE(x)) boolValue]
  8. #define PREF_SET_KEY_VALUE(x, y) [[[NSUserDefaultsController sharedUserDefaultsController] values] setValue:(y) forKey:(x)]
  9. #define PREF_OBSERVE_VALUE(x, y) [[NSUserDefaultsController sharedUserDefaultsController] addObserver:y forKeyPath:x options:NSKeyValueObservingOptionOld context:nil];
  10.  
  11. /* key, observer, object */
  12. #define OB_OBSERVE_VALUE(x, y, z) [(z) addObserver:y forKeyPath:x options:NSKeyValueObservingOptionOld context:nil];
  13.  
  14. #ifdef __OBJC__
  15. static inline BOOL isEmpty(id thing) {
  16. return thing == nil
  17. || ([thing respondsToSelector:@selector(length)]
  18. && [(NSData *)thing length] == 0)
  19. || ([thing respondsToSelector:@selector(count)]
  20. && [(NSArray *)thing count] == 0);
  21. }
  22. #endif

Report this snippet  

You need to login to post a comment.