Last Updated: February 25, 2016
·
2.122K
· alexmaroldi

Useful Macros for iOS Project

//Debug
#define debug(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])

// 2.1 Easy RGB for convenience
#define RGB(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]

// 2.2 Gets the path of a file inside the documents dir
#define FileFromDocPath(filepath) [NSHomeDirectory() stringByAppendingPathComponent:(filepath)]

// 2.3 Removes a file from the documents dir
#define RemoveFileFromDocPath(path) [[NSFileManager defaultManager] removeItemAtPath:[NSHomeDirectory() stringByAppendingPathComponent:(path)] error:nil]

// 2.4 Fast userdefaults getter
#define Setting(param) [[NSUserDefaults standardUserDefaults] objectForKey:(param)]
#define BoolSetting(param) [[NSUserDefaults standardUserDefaults] boolForKey:(param)]
#define IntSetting(param) [[NSUserDefaults standardUserDefaults] integerForKey:(param)]

// 2.5 String Macros
#define DBNULL @"[NULL]"
#define NOT_AVAILABLE @""

1 Response
Add your response

Thanks for sharing list... I have just started iOS development and found one more useful macro for ApplicationDelegate... Like

define ApplicationDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])

over 1 year ago ·