Tuesday, January 11, 2011

ObjectiveResource Bug Fix

Needing to do some Rails-iOS bridging, I've been checking out ObjectiveResource. At first I thought it was dated and also checked out the wonderfully documented and loved ASIHTTP request, which does indeed rock. But really, why parse when you can freeload? 

The only problems I've found with ObjectiveResource is 
  1. How terribly the Google Groups forum works for solving problems. It's also notorious how few comments there are in the code.
  2. It's pathetically synchronous, or perhaps there are just no docs for that. 
  3. If I bring down the Rails server it immediately returns wrong answers, which is just so disheartening I don't know why I didn't give up on it hours ago.
  4. The following problem, which I spent over an hour fixing just now. To be honest, I'm not sure why the fix works exactly, but it's the right fix.
The problem is that ObjectiveResource blows up under iOS 4.x. I actually forget where the call is made to cause it to blow up, but the blowup begins by infinitely recursing and calling a method on NSObject+PropertySupport.h called propertyNamesAndTypes. The fascinating thing about the problem is that the line that causes the blowup is


[propertyNames setObject:[self getPropertyType:type] forKey:propName];

and it's actually the calling of setObject that causes the recursion to spin. I still have no idea why this happens, but here's the fix. Change this line


while (currentClass != nil) {

to this


while (currentClass != nil && [NSObject class]!= currentClass) {

and that's it. Why does this only happen if you set the object on the propertyNames mutable dictionary? I don't know. I'm not really here to solve problems, just make them go away.



THroNG's latest music video: 100% improvised in realtime like a mugging or a marriage proposal.



1 comment:

Kris said...

NICE!! Thank you for this fix! I decided to use ObjResource 3 years ago for my app, as a nice way to interface with rails. In retrospect I wish I would have gone with a more standard JSON parsing system as this thing is feeling more and more fragile with each iOS update.

Anyway I think you saved me a LOT of hours so cheers!