2013-01-03

Pathological Core Data Database in iOS 5

I’ve spent far too long fighting with this bug today, mainly because Apple don’t appear to publish a list of the bugs they’ve fixed between iOS versions. And wow, their bug reporting tool is still styled after the 11 year old OSX Puma! There’s a design that says “we care about your bug reports”.

Anyway, here’s an example of a pathological Core Data database design that will crash iOS 5. It’s an obfuscated subset of the database I’m using in my current app:

pathologicalDB

Attempting to create an instance of “Entity3” and then set its “guid” attribute will crash iOS 5 every single time. What’s most annoying about this bug in the OS is that adding or removing an attribute or relationship anywhere in the object graph fixes the crash. The bug was silently fixed in iOS 6. There’s an example project here:

Comments

Ray on 2013-03-18 at 22:48 said:

Thanks for uploading the sample project. I thought I was going mad trying to figure out why the app i’m working on would work fine in >= ios6 but crash out as soon as I attempted to setValue in ios5 - 5.1.

I was getting the same EXC_BAD_ACCESS (0x1) error you have in your sample project.

If this is an OS bug, then i’ll have to set minimum OS version to 6.0.

Did you find a way around the problem in the end?

Ant on 2013-03-18 at 23:18 said:

Yeah, I added in a new field to the database. Adding or removing a field from the pathological database fixes the problem.

In a related note, I had a bug report a couple of days ago from an iOS 5 user. The problem? I’d just removed a field and therefore recreated the pathological DB design.

I’m looking forward to ditching iOS 5 compatibility for this project…

Ray on 2013-03-19 at 14:25 said:

I just tried this:

  • Added a new model version based upon the currently working one
  • In the new model, added a new attribute (just made one up in an entity)
  • In my appDelegate -persistentStoreCoordinator method, I have the migration code as an option:

[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

I’ve tried running through an updating previous versions and the migration occurs fine, even on ios 5.

Did you do this and it still crashed?

Ant on 2013-03-19 at 14:44 said:

Yep, I’m using the same options. It’s not a migration issue; the example project in the blog post crashes even without an existing database set up.

Ray on 2013-03-19 at 15:23 said:

Ah I see! I’m going to keep digging on this to see if it’s worth releasing an update later to support ios 5.0. I’ll post back here if I find anything - Good luck!