How to use Targets in Xcode

Targets are an extremely yet totally undocumented feature of Xcode. They allow you to write code once, and then build multiple “versions” of the same code base. This makes maintenance and code updates extremely easy across more than “product”. I use those quotation marks because usually an “Xcode Project” equals a “Product” (such as one […]

How to define Preprocessor Macros in Xcode

I’ve often wondered how to use those efficiently, and I’ve just found out how to do it. As always, they’re not difficult to implement – but not documented in a way that simple folk like me can understand it. Be that as it may… Preprocessor Macros can be useful if you’d like to compile two […]

How to check if your app is running on an iPad or an iPhone

Here’s how we check that: // if we’re an iPad if ([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPad) { // do some iPad or iPad Mini specific stuff } else { // we’re on iPhone or iPod Touch } Alternatively you can check the same method for UIUserInterfaceIdiomPhone instead, which is returned when you’re on an iPhone or […]

How to hide navigation elements with swishy animations

You can hide (and show) navigation bars and toolbars from your UINavigationController with extremely funky animations, much like we see in the Photos app on iOS. In the app, when you single-tap the screen, both top and bottom toolbars disappear. Here’s how we do that: Provided you have your view controller embedded in a UINavigationController, […]

Managed Object Context arrives empty when passed via a segue in iOS 5

I’ve just found that passing an NSManagedObjectContext object via a segue in iOS 5 doesn’t work: the property remains empty. In iOS 6 on the other hand this isn’t a problem: the context arrives just like any other property would, and as logic would dictate. Here’s code from an amended Utility Template app: – (void)prepareForSegue:(UIStoryboardSegue […]

How to find out what class an NSObject belongs to

Sometimes you find yourself having a reference to an object (say a View Controller), but you don’t know what class it belongs to. Thankfully there’s a method for this which will work with any NSObject: if ([self.navController isMemberOfClass:[UIViewController class]]) { self.previousTitle = @”Novels”; } In this example we’re testing if our self.navController is a UIViewController. […]

How to define a method that takes multiple parameters

I keep forgetting how to do this… don’t ask me why, it’s not that difficult! So here’s how we define one: – (void)methodName:(NSString *)parameterOne methodNameContinues:(NSString *)parameterTwo; Add more parameters as you please. In theory, the method name is split across these multiple descriptive parts before each parameter is defined. However in reality I find it […]

How to list the contents of an NSURL

On the iOS simulator we have the luxury of peeking inside our virtual devices with the Finder. We can do this by heading over to the Finder, holding down Option and clicking Go. This will bring up the Library, in which you can navigate to Application Support / iPhone Simulator / 7.0 / Applications / […]