Aug 21 2015 0

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

as of version 3 of Python the following command needs to be used

python3 -m http.server 8000

Logging time

https://twitter.com/georgestarcher/status/723923054687076352

macOS Terminal commands

1

launchctl list | grep -v com.apple

Find file on disk (skipping Permission denied’ warnings)

1

find / -type f -name com.tunnelbear.mac.tbeard 2>&1 | grep -v "Permission denied"

Recursively remove .DS_Store files (starting from current folder)

1

find . -name '.DS_Store' -type f -delete

Git commands

Generate list of commits containing the string #changelog’ since the last tag

1

git log `git describe --tags --abbrev=0 HEAD^`..HEAD --pretty=format:'- %s' --reverse | grep '#changelog'
This blog is powered by Blot