views:

969

answers:

2

It looks like the recent Xcode 3.2 has added some code generation niceties that (I think) were lacking pre-Snow Leopard.

I took the following steps:

  1. Define a simple .xcdatamodel model with a few entities, including one (inversible) one:many relationship (an Endpoint has many Subscription objects)

  2. File -> New and select the (icon-less) "Managed Object Class". From that wizard, I selected my classes and I was off to the races.

  3. Until, that is, I tried to build. I get this result and can't figure out:

Undefined symbols: "_OBJC_METACLASS_$_NSManagedObject", referenced from: _OBJC_METACLASS_$_Subscription in Subscription-B5BE258DF28BC03B.o _OBJC_METACLASS_$_Endpoint in Endpoint.o "_OBJC_CLASS_$_NSManagedObject", referenced from: _OBJC_CLASS_$_Subscription in Subscription-B5BE258DF28BC03B.o _OBJC_CLASS_$_Endpoint in Endpoint.o ld: symbol(s) not found collect2: ld returned 1 exit status

What I'd love help with:

  1. If anyone has any ideas of what I just did wrong, that'd be fantastic.

  2. It looks like the only way to get Xcode to re-generate your classes is to File -> New and replace them again, which (among other things) results in duplicate references to the new classes and your old class files uselessly left in a moved-aside folder in your project. Anyone know how to keep these in sync correctly? I haven't found any Apple documentation that covers the new stuff.

+4  A: 

Did you add the CoreData.framework to your project (or accidentally remove it)? That might be the source of the linking error.

Also, I reccomend you check out MOGenerator, by Wolf Rentsch. It's a much more powerful code generator for core data classes that uses the generation gap pattern. It can automatically regen classes every time you save the xcdatamodel while preserving your custom code.

Barry Wark
Thanks for the response. I thought I had, but it's possible I missed it.I looked briefly into MOGenerator, but I didn't take the time to appraise it, because it looked like Apple had just aped similar functionality into Xcode 3.2, and didn't want to add a suddenly obsolete tool to my workflow. Seeing as the Xcode feature isn't even really documented, I may as well spend the time getting to know MOGenerator. Thanks!
Justin Searls
Working on getting MOGenerator and just as an FYI to anyone viewing this question, as of 10/13/09, Xcode 3.2.x has broken the xmo'd integration: http://www.openradar.me/7289446
Justin Searls
A: 

The simplest (and most frequent, and most easy to overlook) way this happens is if you accidentally generate a new set of MOC classes without removing references to the old ones (maybe in a different group in your project or something). I just spent too long banging my head against XCode before I realised this was exactly what I'd done.

Henry Cooke