I mess around with a bunch of different programming languages. There’s always things you forget how to do as you switch between PHP, Java/’Droid, HTML-CSS-JS, and Obj-C. Rather than constantly google the same thing over and over, here’s my short reference list of the things I use frequently, but not enough to have it memorized about iOS, XCode, and OS-X:
- String appending: Simple in Java, but in Objective-C its more like…C. Here’s how:
[NSString stringWithFormat:@”%@ on %@ at %@”, visit.visitType.visitDescription, visit.dateOfVisit, visit.location];
- Date Formatting: Create a formatter and then format the string:
_df = [[NSDateFormatter alloc] init];
cell.date.text = [NSString stringWithFormat:@”Visited %@ %@”, visit.location, [_df stringFromDate:visit.dateOfVisit]];
- How to load content into a webview component:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@”about” ofType:@”html”]isDirectory:NO]]];
- To not use ARC for a specific file include this flag:
- How to dismiss a pesky keyboard:
- App Launch Failure from Xcode
Don’t forget to switch back to a dev signing cert when launching apps from Xcode or the app will hang. Pesky thing I forget.
- If you really hate using iOS silly color formulas use a #define in your code:
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
And then you can do this in your code:
self.backgroundColor = UIColorFromRGB(0x393B40);
- Screenshots – always forget how:
Command+Shift+3: takes a screenshot of the full screen (or screens if multiple monitors), and save it as a file to the desktop
Command+Shift+4: brings up a selection box so you can specify an area to take a screenshot of, then save it as a file to the desktop
Command+Shift+4, then spacebar, then click a window: takes a screenshot of a window only and saves it as a file to the desktop.
- Kill a bad program:
COMMAND-OPTION-ESC – always for get that one!
- To add environment variables to OS-X, create a file called launchd.conf in /etc and add the paths with
setenv MY_DIR /myDirectory/that/i/like
- To add directories to the PATH use /etc/paths – one path per line.
- To create environment variables add a .profile folder to your home directory and do it there.
- To open hidden files in a GUI text editor like Text Wrangler or Sublime, hold the shift button while clicking Open.
Ok – that’s more than ten, but nothing wrong with a bonus!