Aug
21
2015
0
Snippets
- Objective-C (5)
- Python (2)
- macOS Terminal commands (3)
- Git commands
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
BOOL tstFlag = YES;
NSLog( @"tstFlag is set to %@", tstFlag?@"Yes":@"No" );
System Versioning Preprocessor Macros
#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
#define appDelegate ((YourAppDelegate *)[[UIApplication sharedApplication] delegate])
Read Product Name and Version from bundle
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)
#if DEBUG
#warning DEBUG BUILD. Do not submit this to the App Store. Dummy
#endif
Python
Start a simple HTTP server
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
List all non-Apple related Launch Agents (launchctl)
launchctl list | grep -v com.apple
Find file on disk (skipping ‘Permission denied’ warnings)
find / -type f -name com.tunnelbear.mac.tbeard 2>&1 | grep -v "Permission denied"
Recursively remove .DS_Store files (starting from current folder)
find . -name '.DS_Store' -type f -delete
Git commands
Generate list of commits containing the string ‘#changelog’ since the last tag
git log `git describe --tags --abbrev=0 HEAD^`..HEAD --pretty=format:'- %s' --reverse | grep '#changelog'