NSCoding: Painlessly Storing Your Data


If you’ve ever needed to save dictionaries within your apps, you are undoubtedly aware of their biggest limitation: you can only store generic data types (NSString, NSData, NSDate, NSNumber, NSArray, NSDictionary) within them. To be honest, most of the time those generic data types are all you need; but what if you need to do something a little more… robust? This is where NSCoding comes to the rescue.

NSCoding: What is it?

NSCoding is a protocol that defines the methods needed to give a class encode/decode-ability. In short, it allows you to store an instance of a class to disk as a simple chunk of data. When used in tandem with dictionaries, this can become an invaluable (and supremely time-efficient) method of storing data in your application.
Continue reading

NSBundle: Loading External Code Like A Boss


I’ve always known about NSBundle’s external code loading capabilities, but have never had the immediate need to leverage it. However, one of my more recent projects required me to develop in a “host-plugin” model – I finally had the excuse I needed to dive into the advanced features of NSBundle.

The Host-Plugin Model

The “host-plugin” model is an application model where the host application loads code, resources, and settings from external plugins or bundles. For example, suppose a host application lets a user install custom themes. These themes could be included with the host application, or downloaded from the internet. The host application would load these themes as plugins or bundles and grab code/resources from them as needed.
Continue reading

Singletons, There Can Only Be One.


Often the topic of heated discussions, singletons actually can be fairly useful in the right situation. Though many view the “wasteful” nature of singletons as a deal-breaker, they are not always as evil as they’re made out to be.

What is a Singleton?

A singleton (or shared instance), is a class that is only ever initialized once (well, hopefully) and is persistent throughout an entire application’s lifecycle. In practice, different parts of an application can store and read data from a singleton without having to worry about managing separate instances. Naturally, you will not always need to be accessing a singleton. This is the basis of many people’s “wasteful” views on the subject. Because a singleton is persistent throughout an application’s lifecycle, it’s allocated memory will stay occupied until the application is terminated; regardless of if it’s being used or not. Though having un-used allocated objects is never a great thing, the advantages of an always up-to-date data “manager” can sometimes be worth the slight memory hit.
Continue reading

The Wonderful World of Objective-C Blocks


I know, I know. Blocks have been lingering around ever since the iOS 4 days. So why write a post on them now? Because they’re awesome. duh.

Well, that and I feel they are extremely hard to grasp for newcomers (I surely had a difficult time wrapping my head around them at first; not to mention they’re just plain ugly at times – which is a turn off for some)


For those of you who haven’t heard of them, blocks (sometimes called closures) provide an easy way to pass a function as an arguement to a method. Most often, this is used in a “completion handler” fashion. Let’s take a closer look:

[object doAwesomeTaskWithCompletion:^(BOOL success) {
    if(success) { NSLog(@"Awesome task complete!"); }

It’s as easy as that. In this example, object would perform it’s awesome task, then call the completion block that we provide. Neat huh? If you’re wondering where the boolean “success” came from, object’s doAwesomeTaskWithCompletion: method provides it. As with everything, it didn’t just appear out of thin air; but more on that later.

Continue reading

@”Hello, world!”


I finally made the jump to WordPress. Needless to say, I’m more than satisfied with the decision. Unfortunately, because of the migration there is still a lot of work to be done. Tutorials, project info, and everything else will be uploaded as soon as they are ready!