Snippets

Objective-C Snippets

On this page I am keeping a list of Objective-C snippets I come across and use myself

Printing boolean values in NSLog

1

BOOL tstFlag = YES;
NSLog( @"tstFlag is set to %@", tstFlag?@"Yes":@"No" );

System Versioning Preprocessor Macros

1

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

Application Delegate Macro

1

#define appDelegate ((YourAppDelegate *)[[UIApplication sharedApplication] delegate])

Read Product Name and Version from bundle

1

NSString productName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]
NSString productVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];

Never submit a debug version to the App Store again, by Matt Drance (@drance)

1

#if DEBUG
#warning DEBUG BUILD. Do not submit this to the App Store. Dummy
#endif

Python

Start a simple HTTP server

1

python -m SimpleHTTPServer 8000

Logging time

This blog is powered by Blot