Xcode 3.2.1 - Why are Core Data generated Classes resulting in Build errors?
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:
Define a simple .xcdatamodel model with a few entities, including one (inversible) one:many relationship (an
Endpoint
has manySubscription
objects)File -> New and select the (icon-less) "Managed Object Class". From that wizard, I selected my classes and I was off to the races.
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:
If anyone has any ideas of what I just did wrong, that'd be fantastic.
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 cla开发者_高级运维sses 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.
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.
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.
精彩评论