Fun Times with Objective-C Runtime

Good reusable solutions to problems usually come out of necessity rather than luck or leisure.  Over the past 18 months I was always faced with problems of how to simplify the data integrity, security, and aggregation of multiple datasources, usually in big organizations that would then be fed in an iOS app.

The first solution to this issue is to create the "man in the middle".  Essentially a proxy/web services layer that acts as the gateway to all the necessary model objects.  Utilizing tools such as Gearman, CouchDB, MySQL, PHP, Python, Memcache and a little bit of Apache to make everything complete I was able to deploy a lightweight standard response to the iOS app.  As requests from various business groups would come in I found myself taking more and more out of the app and putting that logic into the services layer. Instead of having to rely on the app to handle security, data integrity, computational analysis, image manipulation, etc. I pushed that onto a light weight stack server side that could be scaled easily and mainainted without having to revision the app for basic model object changes.  The added benefits that I saw later on were that I could adapt the response based upon the request…(Android, iOS, mobile web, desktop browser, etc.)

Now that I was concentrating more on feature sets, bug fixes and UI enhancements I was still stuck with having to manage various model classes within the app.  This was a serious pain point to me. I wanted to be able to consolidate the various list and detail controllers that I had down to one instance of each.

Objective-C runtime to the rescue.

Let me be very clear that objective-c runtime is VERY powerful and not for the faint of heart, but when used effectively can be quite useful.  The approach that I took was as follow. 

Use the existing "standard" json format from a web services layer and restructure the "responseObject" so that it gave meta information about the model name, properties for class, which properties should be displayed on the list page and detail page.  By structuring the json  (xml, plist, etc) play load this way I now can push changes to model object and display anytime I want.

In the github project I use an "Employee" object as the example. The app should be able to show a list of employees (title and subtitle) and then a detail page for each employee that would display up to 3 properties.

I have included another json file for "Events" just so that I can show the flexibility. The same list/detail view controllers are now reused for two different objects.

The (current) limitations.
  1. There is an assumption that your list view will use the subtitle uitableviewcell enum type.
  2. Parsing and creation of classes doesn't take into account types other than nsstrings. I have an idea to remedy this, just haven't implemented yet.
  3. What about images?  Most list views have an image associated with it.  What I am thinking about it having a flag set in the properties specifically for images so that they can be loaded asynchronously.
I will be adding in these features.  I am still getting my head wrapped around some of the advanced features of runtime. Below are the links to resources that I used in my research.

Posted on slideshare is the presentation that I gave. It details the philosophical and practical importance of having an SOA that is similar to what I described.  It was heavily inspired by the presentation written on the subject of NPR's SOA.

Presentation References:

UILocalNotification Example Project Using iOS4

One of the greatest new features that is included in iOS4 is the power that developers have to deliver local notifications.  At the time that the first beta was released in April I was writing specs/requirements and project timeline for a potential app which would have ended up taking me about 5 months to develop.  A large part of the project schedule dealt with having to setup/maintain user reminder preferences...the number of reminders, frequency of each one, time zones, etc.  I tried to think of ever solution that I could that didn't involve the server component, but there really wasn't any other way.

UILocationNotification to the rescue.  After looking over the API docs, Apple had provided exactly what I needed and I was able to cut out 2.5 months from the project schedule because of it.

I was able to create an POC app using UILocationNotifications in literally 5 minutes.  It involved two easy steps:


  1. In the app delegate class I added the following method to verify that the event was fired off if the app was running. -(void)application:(UIApplication *)application didReceiveLocationNotification:(UILocationNotification *)notification;
  2. In the -(void) viewDidLoad method of my controller you alloc/init a new UILocationNotification object, set the fireDate which is an NSDate object, what time zone you want, what the notification message(body) should be and then add the UILocationNotification object to the UIApplication scheduleLocalNotification method


There are two possible end results.  The first being that the event is fired off while the app is running in which case you will not see anything. Hence, why I added the NSLog to the didReceiveLocationNotification method.  The second is if you close the app before the notification has fired and in that case you will receive the alert box with your message.

Download XCode Project

Note: This was compiled with iOS4 GM and tested on iPhone 3G/3GS

Create Custom Sized UITableView with Header and Footer Views

I am currently working on a photo gallery/slideshow app and one of the requirements is for the main gallery listing page to have static header and footer that shows the app name, contact information and adverts.  The logical first method of attack is to just setup a UITableViewController subclass, slap some views and subviews to the table view header and footer and get on with the day.  However, the table itself should scroll, but the "header" and "footer" views should remain stationary.  My first approach, I found out quickly, did not work.  Surprisingly, there are a lot of people having issues with custom sized uitableviews in general and the discussions that I saw online didn't provide a very straight forward solution so I decided to create one.

The first big problem that most people run into is that they can't seem to resize the uitableview no matter what frame size they set.  It doesn't matter if you do it programmatically or through Interface Builder it still takes up the ENTIRE screen.  That is because they have subclassed UITableViewController.  To be honest I am not sure that happens "under the covers", but the custom frame sizes/locations are ignored.  You must make your controller a subclass of UIViewController and then add your UITableView as a subview to the your controllers view.

For example:

At this point your frame size and height will be respected.

In my example I setup a simple UINavigationController project with two controllers.  The first has a header view, footer view and uitableview.  The second "detail" controller just has a UILabel with placeholder text.  Everything is built programmatically so that you can adjust frames and positions easily as well as any other customizations you would like.  Comments/suggestions are always appreciated.

Download Project

Google Fiber for Memphis

If I can't get to Google then why not bring Google to Memphis.  The latest project that I worked on is the promotional site to campaign for the Google Fiber project to select Memphis as one of the cities for the it's ultra-fast network infrastructure.  It, by-far, has been one of most rewarding endeavors that I have had the privilege to be apart of.  Not only because of the different technologies that were used for the site (jQuery, Google Docs, Google Buzz, Twitter, Facebook, YouTube, my custom ZF CMS), but also I was able to give back something to the community in hopes of growing not only the local economy, but also foster greater innovation for the rest of the world.

Support Memphis in it's bid for Google Fiber.  Due your small part in something BIG.

The Drive to Build More

Based upon the myriad of tweets over the past three months or so, most who follow me know that I have been working on my first iPhone app.  Well, first to submitted to the app store.  I have finished an app for work and have started on another for  Though the app hasn't hit the stores YET, I already have the inspiration to build more.  EraseUrX has by far been the most rewarding project I have worked on in the past three years.  Even if I don't make a lot of money, it truly has been self satisfying to just complete this project.  I can't wait to get started on the next one not only for the challenges that await, but also I know that I be able to put it in the App Store faster.

There has been a lot of criticism of Apple's approval process in the App Store, but over the past three months they have made great strides to improve this process and it has benefited developers greatly.  In addition, there are rumors floating around of a possible upcoming announcement of the 4.0SDK and a new phone device, which if the 3.0 release is any indication of the amount new features added to the phone, then the 4.0 release will give developers even more tools to increase the usability and features in our apps.

Hopefully, the saying is true...

If you build it they will come.

2010: Location, Location, Location

I guess you could really argue that the "mobile revolution" was started when Apple first released the iPhone, but 2010, I predict, will be a year full of explosive new mobile technologies and adoption.  2009 saw a huge spike in the adoption of smart phones, as well as, the release of new platforms, devices, and applications.  For the past 10 years I have focused on desktop web apps, but am VERY excited about the breakthroughs and innovation that has evolved in the mobile arena, especially with the offerings coming from Google and of course Apple.  As a consequence, 80% of my focus will be on mobile applications, both native and web.

2008 was the year of "web 2.0", 2009 was consumed by social media, and I predict that 2010 will be a digital Magellan on steroids with the Location Based Services popping up everywhere.  Evidence of this is already presenting itself, with the purchase of GeoAPI from Twitter, Google is offering "turn-by-turn" directions for free in the latest Android SDK, and Apple purchased a map tile software company.  The question will be how will all this data and the services used to manage the data be best served for the consumer.  The days of showing pins on a map are growing quite old.  It is time for more forward thinking, which is what the before mentioned companies do best.