Dynamic classes with Objective-C

May 27th, 2009 aaron 2 comments

I recently worked on a project for a client that had a lot of data coming from a web service as JSON. The data was comprised of associative arrays (or dictionaries as they are known in other languages) with each key pointing to a set of data. Each of those sets of data can be used to instantiate one of several custom classes I created in Objective-C. Using TouchJSON from the handy TouchCode library I was able to translate the incoming JSON string to an NSDictionary object. An NSDictionary of data is much nicer than a raw string of JSON, but what I really wanted was to take each data set in the JSON and use it to initialize the custom classes I created.

My first pass at this was overly repetitive. I wrote a bunch of methods on my ResponseHandler class (which, as the name suggests, handles responses from the web service) that would consume each entry in the dictionary and return an instantiated object. So I had a bunch of methods on the ResponseHandler that looked like “newJSON”. Kind of messy if you ask me and I was not keeping in line with the DRY principle.

I did some digging into Objective-C and found that it is possible to do some nifty things with the language. One of them being dynamic class creation. With this new bit of knowledge, I had a clean way to resolve my lack of DRYness (…and incidentally, made me happy since I come from a Python background where dynamic class creation is relatively normal).

Lets take a contrived example of a web service which returns data about various shapes to the client. The JSON data retrieved from the web service can be used to instantiate two shape classes: Square and Circle.

If we make a request to this web service we get back the following JSON:

{'SquareObject': {'width': 10, 'height':10, 'center':[5,5]}, 'CircleObject': {'radius':10, 'center':[2,2]}}

Again, with TouchCode’s TouchJSON class, the JSON string above can be turned into cocoa objects.

The shape classes have the following interfaces:

@interface Square : NSObject {
    NSNumber *width;
    NSNumber *height;
    CGPoint center;
}
 
- (id)initWithJSON:(NSDictionary *)jsonData;
 
@end
 
@interface Circle : NSObject {
    NSNumber *radius;
    CGPoint center;
}
 
- (id)initWithJSON:(NSDictionary *)jsonData;
 
@end

Notice I have a method on each class that has the same signature:

- (id)initWithJSON:(NSObject *)jsonData;

This method will be used to instantiate each class with the appropriate data.

The final setup requirement is to create a NSDictionary that maps the JSON keys to Class objects. It lives in my ResponseHandler class where I also instantiate the shape objects, but you can do this where ever makes sense for you.

NSDictionary *classMap = [NSDictionary dictionaryWithObjectsAndKeys:
  					   [Square class], @"SquareObject", [Circle class], @"CircleObject", nil];

In my ResponseHandler class, where I am instantiating the shapes from JSON, I iterate through the expected keys in the NSDictionary that was created from the JSON string (jsonData) and send the initWithJSON: message to each class like so:

NSMutableArray *tmpObjs = [[NSMutableArray alloc] init];
NSObject *anObj;
for (NSString *aKey in [classMap allKeys]) {
	anObj = [[[classMap objectForKey:aKey] alloc] initWithJSON:[jsonData objectForKey:aKey]];
	[tmpObjs addObject:anObj];
	[anObj release];
}
self.dataObjs = [NSArray arrayWithArray:tmpObjs];

That’s it. A relatively simple way to dynamically instantiate classes based on incoming data. If you want to see the complete program I used to write this program, you can find it here.

Categories: Uncategorized Tags:

iPhone: For Business or Pleasure?

April 28th, 2009 john No comments

Apple iPhone Owners Favor Personal Uses, Not Business

So you can look at this survey from Compete in many ways.  Here is my take.

Simple answer: Because not enough businesses understand what the iPhone is capable of. 

Most of the apps downloaded are games and weather.  But is it cause that is what people want and use, or cause there is no choice? Businesses make applications but they are all so very small on fuctionality.  Truly they have concentrated more on branding and asthetics then what they could truly give the end user.  When businesses begin to be more innovative and creative you will see the iPhone go to places we have not yet thought of. 

Imagine doctors using it in the hospital for medications, airline pilots having back up gauges when dashboard goes out, or sales men with presentations ready at any moment.  Applications dont have to be for America.  They can be just for your business.  Now that is a cheap, highly informative device that can increase your profits and efficiency. I ask all businesses to take over the iPhone so you can take over the competition.  See what iPhone possibilities are out there.

Categories: Uncategorized Tags:

Should there be a shelf life for iPhone apps?

April 21st, 2009 john 1 comment

Should there be a shelf life for iphone apps? Would this cause more harm or more good to the iTunes store?
Lets look at both.  First the harm.  The harm this would cause is that great apps would be unnecessarily pentalized because of a clock rather than their performance and popularity.  A great app should not come to an end because of a calendar date.  The other effect would be to discourage developers.  If you were to work really hard on something knowing it would only last a year or so would they still put forth the same kind of effort?  What about the people?  Perhaps the people should decide if they want the apps around or not.  So maybe a system where unpopular or rarely downloaded apps would be dropped for poor performance.  That would ease the search of what iPhone apps you were looking for.

The good of the shelf life.  The main advantage is to cycle through and turn over the store.  It would get rid of alot of unnecessary applications.  Would also give other apps a chance.  If something is ranked in the top 10 its very hard to overthrow it when it has the exposure.  Even if that app was not as good, just being in the top 10 would keep it there from shear download amounts.  Now Apple will say it has a formula for helping the natural order of things, but they will not say.  I think not because of security of manipulation but because they have not found a good solution yet.  A shelf life would clean it up.  Developers could always reupload their app and let it fight it out again.

There are many pros and cons to this but as we approach 50k apps this year or next there needs to be a system to find what you want.  And please, don’t let Google do it.

Categories: Uncategorized Tags:

Who Makes iPhone Apps

April 13th, 2009 john No comments

Who makes all those great iPhone apps?  How do people find others to write customize apps for them?  The searches you do can be alot to dig through.  When searching for a company to make your iPhone application consider the following:

  1. Price – Yes price does matter the most, because it matters the most to you.  When looking at companies dont just look at the overall sticker but the hourly charge on development hours.  You can and will have changes through the process but if you know hourly one company is better than another you will be better off.
  2. Quality – Ensuring your app works, does not crash the iPhone and will have improvements made should a bug be found (and most likely will).  You can assess quality based on the developers resume.  Applications have not been around so find out what they did before they came into the business.  That will tell you more than the apps they made.
  3. Time – Will your new iPhone application take 6 months to build or longer? What will your market look like in the future? Assessing where you are and where the competition will be can be a huge factor in pulling the trigger on building an app.  Try to find reasonalbe time frames and your true expectations up front.
  4. Communication – Do your new iPhone app developers communicate effectively? accurately? timely? honestly?  This will make your job easier and lessen the time it takes to build.

Following these main points and asking the right questions first can help you narrow down your search.  Also don’t be afraid to call them, as in point number 4, you can do more in 5 min phone call then 36 emails over the course of two weeks.

Categories: iPhone creation Tags:

Five Reasons You Might Want an App

April 7th, 2009 john No comments

Great Reasons to Get the App Going Now

  1. Engagement 101. If done right, an app is an opportunity to deeply involve the consumer and a way to extend dialogue after a campaign has ended.
  2. It can raise brand loyalty. The more times consumers interact with a brand, the greater the chances they will gravitate toward it when they’re ready to buy.
  3. You’ll be ready when the app market really explodes. Within five years, In-Stat expects handset makers to ship a total of more than 100 million units that are app-compatible, so now is the time to gain some experience.
  4. It’s where the eyeballs are. The numbers are compelling: some 800 million downloads from the iPhone App Store.
  5. IPhoners have great demographics. Their income specifically makes them a very desirable target, and they’re ravenous multimedia users. According to AdMob, iPhone generates half the smartphone traffic in the U.S.
Categories: Uncategorized Tags:

iPhone 3.0 Coming Soon

April 6th, 2009 john 1 comment

iPhone 3.0 Software Announced!

iPhone 3.0 Software Announced! – Today, From their headquarters in Cupertino, California, Apple Inc. Announced New Software version 3.0 that will include many new features and be available for the iphone as a FREE download sometime this summer. I’m sure that sometime in the immediate future, that apple will announce a date that the new software will be available. There are so many new features that I don’t even know where to begin. First off, I know the first question many of you will have, what about copy and paste? Well, I am proud to announce that Copy and Paste is going to be a New addition to the software upgrade! It will save so much time and be so convenient for everyone. It sure took them long enough!

Another feature that I want to highlight and am proud to announce for you Iphone junkies like me is that MMS has been added as well. I can’t tell you how many times I have wanted to send a picture to a friend in a text message but I couldn’t because it wasn’t supported in the Iphone. This will make my life much easier and happier now that I will be able to send picture messages once again. What about other new features? Well, I could tell you about them one by one, but to make it easier on both of us, I will use a simple picture that was taken at the media event that helps to summarize everything that will be added.

New Iphone 3.0 Software Features.

New Iphone 3.0 Software Features.

Seeing that list of features is really exciting but that’s not even the good part. In addition to those ‘minor’ updates, here is more updates that will be available in the new software package:

In App Purchases
Peer to Peer Connectivity
Accessories API
Maps API in apps
Turn by Turn direction
Push Notifications
New API’s allowing access of various iphone hardware/software
bluetooth connectivity
Landscape mode for Email, text messages, and everything else
Voice Memos
Search for apps like mail, ipod, calendar
Spotlight
New Redesigned home screen
MMS
Cut, Copy, and Paste
Stereo Bluetooth
Tethering Support

Apple really has outdone itself this time and once the new software is ready for download, that will help shore up the iphone’s weaknesses and make it, one of, if not already, the most, dominant phones on the market today. I can’t wait to get my hands on it!

Categories: Uncategorized Tags:

Phodder is Growing

March 18th, 2009 john No comments

Pheeder, the website to iPhone app service, is steadily rising in popularity.  But new venues are on the rise.  Soon you will be able to incorporate advertising into your Pheeder.  You will be able to have categories.  The application can support chat.  And we can now customize our application to suit your business needs.  So if the package is not quite what meets your needs, contact us and let us know.  We will work hard to make sure you get the iPhone application you need to get your business name out there.

Phodder

Categories: Uncategorized Tags:

New Demo Available

March 2nd, 2009 john No comments

You can now see our new demo of the Pheeder app as well as some great pictures to give you an idea of the final product you may have.  We hope to continue to update our site to give you the best experience possible.

If you have any feedback or suggestions please leave a comment below.

Categories: Uncategorized Tags:

Mobile Ads Stick

February 21st, 2009 john No comments

According to a study released today by eMarketer, and reported on paidContent.org, mobile ads perform better thaniphone ads on other media. With all the bad news about advertising this is a bit of a breath of fresh air. The data was put together by eMarketer based on aggregated findings from social network Limbo and research firm Gfk NOP , which surveyed mobile users. Overall, it appears as if iPhone users are the leaders of the pack in responding to these ads. Whether they buy anything was not revealed.

The mobile ads apparently stayed longer in the heads of those viewing them and they did take click through actions more often. Some other highlights of the report include:

  • 41 percent of iPhone users recalled the ads they saw on their phones versus 33 percent for non-iPhone users. This can be compared to TV which has 10 percent recall rates, streaming video with 21 percent and podcasts at 68 percent.
  • One third of mobile users who recalled an ad responded to it in some way—that figure jumped to two thirds for iPhone users. iPhone users were twice as likely to browse the web on their phones as non-iPhone users.
  • The mobile ads most likely to be viewed were text messages.

There is large percentage growth in this advertising sector (40%) but it is relative to the smaller size of the total market which is forecasted at $2 billion for this year by JP Morgan. Seeing the obvious dominance of iPhone users in this segment one wonders what would happen to the industry if there were more carriers who could sell the iPhone. Also, will iPhone users turn into their own demographic group regardless of gender or age or any other factor other than their phone? So many questions.

Categories: Uncategorized Tags:

Phodder Pheeder Coming Soon

February 18th, 2009 john No comments

What could be better than reading this blog online? Well on your iPhone of course.  Our favorite Pheeder coming out will be our own Phodder Pheeder.  It will showcase our great features and ease of use.  In the future, we hope to demonstrate the added advantage of having an iPhone application drive traffic and increase brand loyalty.  As soon as its live on iTunes we will post again with the information.

phodder-pheeder

Categories: Uncategorized Tags: