SMModelObject

This looks of interest for helping out with that model code you always find yourself writing:

Simplify your models with SMModelObject

For almost every app we’ve made, I find myself writing “model classes” to store structured data and logic. For instance, when you search for a book in the Barnes & Noble app, we fetch book results from an XML-based API and parse the XML into Cocoa objects that get passed around to our Controllers and Views…

Yep, sounds pretty familiar.

… Objective-C makes it easy to introspect classes at runtime, so we’ve created a simple base class called SMModelObject.

Using runtime introspection, SMModelObject can do lots of great stuff for free:

  • Automatic release of properties in -dealloc
  • Automatic implementation of NSCopying to make true “deep copies” of objects
  • Automatic implementation of NSCoding so you can archive/unarchive your model objects to disk for state saving or for the clipboard
  • Automatic -isEqual and -hash implementation to compare model objects by value

Sounds helpful, doesn’t it now? Source is on github, check it out!

h/t: @joe_carney!

Alex | December 1, 2010

Leave a Reply