iOS Archives

These posts are syndicated from my iOS Dev Diary over at pinkstone.co.uk.

The format is slightly different with more code snippets and less explanations. I had originally designed it as a notebook in iOS Development – now you can follow along if you’re interested.

How to store a BOOL as NSNumber

You can create an NSNumber with a BOOL like this: BOOL myBool = YES; NSNumber *boolNumber = [NSNumber numberWithBool:myBool]; NSLog(@”boolNumber is %@”, boolNumber); // gives 1 for YES and 0 for NO It is technically the equivalent of creating an NSNumber with a literal @1 or @0. To turn the NSNumber back into a BOOL […]

How to test the size of an NSDictionary (in bytes)

The NSDictionary class doesn’t have a length property that can tell us how much memory is being used for storing the whole lot. Usually we don’t really care how big our variables grow – but if you’re storing that dictionary somewhere with potentially limited space (such as iCloud Key/Value storage), it may well be of […]

How to create a UITabBarController in code

Tab Bar Controllers are setup with an array of view controllers. We’ll create those first, then we simply give said array to our tab bar controller. In this example, this is a subclass of UITabBarController: – (void)viewDidLoad { [super viewDidLoad]; // let’s create several View Controllers with different colours each ViewController *vc1 = [self createViewcontrollerWithColor:[UIColor […]

How to swap out a store file in Core Data

You can switch out the NSPersistentStore file in your running Core Data app by first adding your new store file, then removing the previous one. Once done you must execute your fetch request again so that the new data is available. Hot-swapping stores assumes both NSPersistentStore files are based on the same model. It’s like […]

How to convert a file path into an NSURL (and back)

To convert a file path into an NSURL: NSURL *localURL = [NSURL fileURLWithPath:localPath]; To create a local path from an NSURL: NSString *localPath = [localURL filePathURL]; NSURLs can also be created directly from an NSString: NSURL *yourURL = [[NSURL alloc]initWithString:@”http://wpguru.co.uk”]; // or NSURL *yourURL = [NSURL URLWithString:@”http://wpguru.co.uk”]; If you’re ever tried to pass a local […]

How to find your own apps in Xcode

Sometimes it can be difficult to find which of your own apps are installed on a device, especially when you’ve made so many over the years and also have installed countless ones from the app store. Here’s how to list “your apps” in Xcode 5: connect the device head over to Window – Organizer – […]