gui cocoa

Core Data Lightweight Migration

I have had a few people ask me about data migrations in Core Data, so I thought I'd share my experience. For those of you who don't know, Core Data is Apple's persistant storage framework. It allows you to define your object graph in a graphical editor, performs validation for you and manages the lifecycle of all of your persistant objects. (More info can be found here: Core Data Programming Guide)

So the question people often have is "How do I change my managed object model for my next app version?". Providing that your changes fit a certain set of operations, you can tell Core Data to perform an automatic lightweight migration.

A few of the allowed operations are:
  • Adding new attributes
  • Making existing required attributes optional
  • Making existing optional attributes required (if you provide a default value)
  • Renaming an entity (if you set the ranaming identifier)
  • Renaming an attribute (if you set the ranaming identifier)
To start a migration, make these changes on your model:
  • Create your new model version
  • Make changes
  • Set your new model version to be the current version
Next we need to edit some code. When you setup your NSPersistantStoreCoordinator, you use addPersistentStoreWithType:configuration:URL:options:error: to add a store to the coordinator. The default Xcode template for a Core Data application fills in nil for the options: parameter. We are going to change that.

Setup an NSDictionary with these values and pass it to that options: parameter.
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
  [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
  [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
After you have this setup, changes you make to your model versions will be infered by the Core Data stack at runtime. If you have changes to make that don't fit the lightweight migration requirements, or are targeting Mac OS 10.5, you will need to create a mapping model manually (more info on that here: Mapping Overview)

August 30, 2010 06:42 PM UTC • caleb davenport


MyClasses for iPhone Version 3.0

Today, MyClasses got a major update. Among the new features are:
• an all new user interface
• unified add and delete buttons
• calculates your GPA in-app
• schedule reminders for assignments that will show even if the app is in the background (iOS 4 only)
• built for fast app switching

Head over to the app store to get your copy!

August 03, 2010 10:47 PM UTC • caleb davenport


Adventures With iAd

When iOS 4 launched I decided to include an extra revenue stream in my free app, MyGPA. I took the leap into the unknown world of advertising. The tool I decided to use is Apple's iAd framework and I would like to share a few thoughts on that with you now.

The implementation of iAd couldn't have been simpler. Twenty lines of code or so is all that is needed to create and display (with animation of course!) an iAd.
ADBannerView *banner = [[ADBannerView alloc] init];
banner.delegate = self;
banner.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
CGSize bannerSize = [ADBannerView sizeFromBannerContentSizeIdentifier:ADBannerContentSizeIdentifier320x50];
banner.frame = CGRectOffset(banner.frame, 0, self.view.bounds.size.height - bannerSize.height);
banner.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
[self.view addSubview:banner];
[banner release];
And a quick conditional check as simple as
if (NSClassFromString(@"ADBannerView")) {…}
which allows the same app to run (without ads) on iPhone OS 3.x devices.

Of course for someone like me, programming with iAd was the easy part. Once the app with iAds went live, I had to learn the terms and metrics that are common to advertising (which I still don't know if I fully understand).

The most interesting part by far is the number of ad requests that my app generates on a daily basis. I average 1,200 ad requests a day. That means that 1,200 times a day, users in 36 countries open my app to see their calculated GPA. For a college kid who is just here to learn, that's not too shabby.

When all is said and done, you're left with an elegant banner in your app that looks like

July 10, 2010 06:11 PM UTC • caleb davenport


MyClasses Promo Codes

Here are some promo codes for MyClasses:
  • WWK9ER3K6ARM
  • TPXTPNAENLKL
  • XLJWYLJAT3HA
  • JPNE67NY6KRA
  • NTJE4JWWTW97
  • N7FHT9LJRALX
  • 9PAPWRX79AWF
  • YKX9LR9M6F7P
  • PT9AXWN73LNN
  • 4X66P49RMF47

June 16, 2010 02:34 AM UTC • caleb davenport


Brand new website!

So what's new about my website? It has been written from scratch in Ruby on Rails. My adventure with RoR has been nothing short of incredible. I want to thank Marshall Huss (@mwhuss, two guys) for introducing me to Ruby, the Rails platform, git, TextMate, and his choice RoR hosting provider, Heroku (yeah that's right, FREE HOSTING!).

I would also like to say goodbye to my old friend, PHP. It's been great, but you're not object-oriented, you don't come MVC out of the box, and I don't want to touch SQL.

Now it's time to get back to iPhone...

June 05, 2010 04:53 AM UTC • caleb davenport


MyClasses On Sale!

Ahead of a few upcoming updates, I am placing MyClasses on sale for FREE! Pick up your copy in the app store while the sale lasts.

April 16, 2010 04:37 PM UTC • caleb davenport