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

How to display a UIImage from an NSURL

If you’re displaying images from the main iOS bundle, things are fairly straightforward: self.imageView.image = [UIImage imageNamed:@”Amy.png”]; But if you have an NSURL to your image then it’s not as easy. It took me some digging to find out that you have to convert the URL into NSData first, and then display the data: NSData […]

How to copy a file from the Main Bundle into the Documents Directory in iOS

You can do this either by using paths or NSURLs. Apple recommends using NSURLs, so here’s how it works. In this example we’re copying a file called “Amy.png” which exists in the app’s main bundle. // file URL in our bundle NSURL *fileFromBundle = [[NSBundle mainBundle]URLForResource:@”Amy” withExtension:@”png”]; // Destination URL NSURL *destinationURL = [[self applicationDocumentsDirectory]URLByAppendingPathComponent:@”Amy.png”]; […]

How to use Core Data with multiple Store Files

Sometimes it can be useful to split your Core Data Store File across multiple files. For example, one file could live on the local file system, while the other could live in iCloud. We can do this by telling the Xcode Model Editor to add more than one Configuration, each of which can be allocated […]

How to create an NSDate object

The easiest way to create an NSDate object is to create “right now” with our convenience method date: NSDate *myDate = [NSDate date]; But if you want to create a date object with a date such as your birthday it gets a little bit trickier, and – more importantly – much less obvious. To do […]

How to display the full month from an NSDate (such as “February”)

There was me thinking I’d have to whip out NSDateComponents and NSCalendar – but my mind works too complicated at times. All we need to do this is our good friend the NSDateFormatter and the Unicode Date Format MMMM – let’s check it out: // create today’s date NSDate *myDate = [NSDate date]; // create […]

How to create Linkshare Affiliate Links to iTunes Products

One of the worst ever interfaces i have ever come across is that of Rakuten LinkShare. Even before they’ve been bought by Japanese giant Rakuten it was bad, and it hasn’t been improved since I’ve signed up with them in 2008. Lucky for us we don’t have to use their interface to get links to […]

How to create a UIBarButtonItem in code and make it call a method

Some things are really easy to do via a Storyboard – but when you want to create the same thing in code I frequently forget how to do it. Turns out it’s equally simple: this example assumes you have a View Controller which is embedded in a Navigation Controller (so it already has a UINavigationBar […]