How to create a Facebook Like button in your iOS App

Adding a Facebook Like button to a website in HTML is extremely easy, thanks to Facebook’s Developer API. But it’s not as straightforward to implement it in an iOS App. Thanks to UIWebViews we can create a small web view, perhaps 80 pixels tall, and load the Facebook Like button into it. Here’s how: – […]

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 […]