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 load data in iOS

Here’s how you load data you’ve previously saved with NSUserDefaults. Since you only load data once I’d put this in the AppDelegate.m file (as applicationDidFinishLaunching) or in ViewDidLoad if you have a single view application: // let’s load our data if there is any NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; int theNumber = [defaults integerForKey:@”theNumber”]; NSString […]

How to save data in iOS

There are several ways to save and retrieve data for persistent storage (i.e. when you close your app and open it again). This is the easiest one I can think of: NSUserDefaults. Here’s an example that saves a text field from an IBOutlet. We’re saving both a string and an integer. We can use this […]

How to rename your iOS App in Xcode 4.x.x

Find the info.plist file (in the Supporting Files folder). Say your app is called MyApp, then you’re looking for a file called MyApp-info.plist Say hello to a scary list of key/value pairs In here, find the Bundle Display Name Change it from the default ${PRODUCT_NAME} to your title Build and see your title underneath your […]

How to add a Framework to Xcode 4.x.x

First head over to the top left corner of Xcode. Click on the Project Navigator to show all your files. Next click the big blue A icon right at the top of that list. Just right of it you see two headings: Project and Targets. Click on your app name under Targets. If this pane […]

How to send an email in iOS

This is tricky but doable. We’re using the MFMailComposeViewController protocol for this (don’t ask). This will open the mail app on your device. Older devices without mail sending capability will crash when you call this method so we’ll check before we do this. if ([MFMailComposeViewController canSendMail]) { MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init]; mailer.mailComposeDelegate = […]

How to exchange data between View Controllers

If you have two view controller classes you probably want to exchange data between them. Thanks to two methods we can do that, provided one view controller is presented via a modal segue. Here’s how it works step by step. Imagine you had two labels on each View Controller. We’ll call them myLabel1 and myLabel2 […]

How to add a second View Controller

Here’s how you add a new View Controller to your project and switch to it via a segue: open a new Single View project add am Objective-C class and select subclass of UIViewController (we’ll call it MyViewController here) in MyViewController.h, import the other ViewController.h and vice versa, in ViewController.h, import MyVewController.h too head over to […]