How to avoid Redefinition of 'Category' as different kind of symbol error in Xcode

I got a weird error in Xcode 5.1 today while developing a Mac App which serves as a data entry tool for an iOS app: Redefinition of ‘Category’ as different kind of symbol. The weird thing is that the Mac App builds and runs fine, but when I import the model over to iOS I get an error at compile time:

Screen Shot 2014-05-08 at 19.09.19

The puzzle’s solution lies in something called “Namespacing”. Not that I even remotely care or pretend to understand this, but in a nutshell it means that the name Category is reserved and already defined in /usr/include/objc/runtime.h:

/// An opaque type that represents a category.
typedef struct objc_category *Category;

What that file is or where it comes from will forever remain a mystery to me, just like why it’s not a problem in a Mac App. I could probably try to figure this out for the rest of my days but really: life’s too short as it is. Let’s just

  • rename the Category entity
  • regenerate all NSManangedObject sub classes
  • remember Category as an evil string for the future

and be done with it. Note that you must rename the Entity as well as the Class it creates, and for good measure re-create all your NSManagedObject subclasses:

Screen Shot 2014-05-08 at 19.27.39

I guess that’s why at the beginning of a new Xcode project we have the option to prefix all our classes (which would undoubtedly avoid such problems in the future).

For those who care:





2 thoughts on “How to avoid Redefinition of 'Category' as different kind of symbol error in Xcode

  1. Any other suggestions to make this error go away? It’s been in one of my apps for years and Xcode JUST started complaining about it (after upgrading). I’m not sure recreating my model is feasible at this point because thousands of users will need their data migrated (yuck).

    1. Not that I know of, Chris. But the migration should be fairly unspectacular as you’re only changing a single property there. Simply add another version to the model, add a prefix (or suffix) to the culprit attribute, then infer mapping automatically in your persistent store coordinator. Core Data should do the rest.

Leave a Reply