Latest Articles

Use the navigation at the bottom to see older articles

How to add a Search Display Controller to a UITableView (in code)

We’ve recently discussed how to deal with a Search Bar and Search Display Controller using Interface Builder. You can however do this in code too. This can be useful if you don’t want to make all the relevant connections in every Storyboard. This example assumes you have a Table View (self.tableView) to which you’d like […]

How to add a System User Account on Linux (CentOS)

On both CentOS and Red Hat Linux systems you can easily create new user accounts with their own home directories. Here’s how you do this from the command line. I’m assuming you’re logged in as root, and the new user we’d like to create is called “testuser”: useradd testuser Let’s give our testuser a password … Read more

How to parse a JSON URL in iOS and Cocoa

Both Cocoa and iOS have built-in methods to parse (and generate) JSON data using NSJSONSerialization. Most commonly you’ll want to call a URL with parameters which will return some data. You take this output and tell Objective-C that it’s JSON, then typecast the return to an array or a dictionary which in turn lets you […]

How to use a Selector

Just a quick reminder before I forget (again) how selectors are called: Some of Apple’s pre-written methods use whats known as a Selector. Here’s an example method that uses a selector: // create a bar button item UIBarButtonItem *linkButton = [[UIBarButtonItem alloc]initWithTitle:@”My Title” style:UIBarButtonItemStyleBordered target:self action:@selector(myMethod)]; Notice how the selector is created on the second […]

How to remove the first n characters from an NSString

There’s a convenient method for that by the name of substringFromIndex. This example removes the first character: NSString *complete = @”12345″; NSString *cutOff = [complete substringFromIndex:1]; NSLog(@”%@”, cutOff); // cutOff is now 2345 substringFromString takes only one parameter which specifies where to start the new string. The first character is 0 based, like in arrays. […]

How to create a Fetch Request in the Xcode Model Editor

You can create Fetch Requests in the Xcode model editor, including a Predicate. These are somewhat easier to setup. To create one, select your .xcdatamodeld file, then head over to Editor – Add Fetch Request. Give it a catchy name and a filter property, and much of the above code becomes obsolete. Here’s how you […]

How to retrieve a Managed Object in Core Data Fetch Requests

Retrieving Managed Objects is somewhat more complex than creating them, mainly because you can filter what you’re getting back rather than retrieve everything that your store file has to offer. Let’s first illustrate a basic NSFetchRequest. For the following examples I’m using the iOS Master/Detail template which provides an Entity called Event with a property […]