Entity.h and Entity.m incorrect import for relationship

Hi! I had an old Core Data Entity, with relationship to AnotherEntity

@property(nonatomic, retain) AnotherEntity *anotherEntity;

In AnotherEntity.h a have an attribute

@property(nonatomic, retain) NSString *title;


I've modified some of Entity's attributes (added new one) so after generating new NSManagedObject subclass Xcode generated 4 new classes: Entity.h, Entity.m, Entity+CoreDataProperties.h and Entity+CoreDataProperties.m

Previously AnotherEntity.h had been imported in Entity.h, but this time Xcode imported it in Entity.m. So trying to access entity.anotherEntity.title gives me error Property 'title' cannot be found in forward class object

I've solved it, importing in Entity.h, but wonder if it's correct and Xcode was wrong importing in .m or it's me doing something wrong?

The code can work either way.


If the class definition gets imported in the header file, then that forces everyone who imports that header file to process the import. Or that can be avoided through the use of @class statements.


If the class definition gets imported in the implementation file, then that forces everyone who meaningfully references the class to import it when they use it. When the compiler gave you the message "Property 'title' cannot be found in forward class object" that was it telling you that you need to import the definition.


There's a big argument about avoiding cluttering name spaces, reducing the chances for name-space collisions, reducing the amount of time it takes to compile each file, avoiding circular defitions, and so on. In other words, it's one of those organizational arguments about two steps above arguing about two space, four space, or actual tab indents. 😐


But, in the end it boils down to:

- The newly generated header files use @class to avoid needing to import the files.

- That means that your implementation files need to import more header files than they used to.

Entity.h and Entity.m incorrect import for relationship
 
 
Q