Kheldar
Kheldar

Reputation: 5389

Forward declaration in Objective-C in child class

In our project, we have a series of classes that used to work fine. In Xcode 4.1's latest update the behaviour seems to have changed, highlighting an issue in our code that wasn't detected before.

Here's the situation, using example classes to narrow the problem down:

An error is shown at this step:

**ARC semantic issue:**  
Receiver type 'ElementalObject' for instance message is a forward declaration

Since the Child class does not redeclare, or reassign, theElementalObject, I do not see why it should contain an import to the ElementalObject header file, which is already imported in the Parent implementation file.

It seems, unless I'm also misunderstanding that, that the compiler tells me otherwise. Could anyone clear this up?

Upvotes: 2

Views: 508

Answers (1)

BergQuester
BergQuester

Reputation: 6187

You do need to import ElementalObject.h in the child class's .m.

While the child class is not declaring the property, nor assigning it, it is trying to call methods on it. Unless the header for ElementalObject is imported, it has no idea what methods theElementalObject responds to.

Basically, if you do anything with a class, you must import the .h somewhere for the .m that uses it.

Upvotes: 3

Related Questions