Mends.One

Prefixing CoreData generated classes

Xcdatamodel, Core Data, Xcode4.6

In my XCode project I have two data models (.xcdatamodel) and want to generate NSManagedObject-derived classes for the entities in each of these models. The problem is that both models contain an entity with the same name. How can I get these classes generated with a prefix so as to avoid link errors due to name collisions similar to that described in this similar question?

2
H
HairOfTheDog
Jump to: Answer 1

Answers (1)

Give them different class names, that's all. Entity names and class names don't have to be the same. The generated classes will use whatever name you provide.

For example, if you had an entity Person, you could add a prefix Foo to its generated class name:

enter image description here

When you generated classes for this entity, you would get FooPerson.h and FooPerson.m. Use different prefixes in different models, and you get different classes.

On a related note, you'll get much better results if you use mogenerator to generate your classes than if you use Xcode's built-in class generation. It's a lot more flexible, and it makes it much easier to keep your generated classes up to date if you change the model.

5
T
Tom Harrington

Related Questions