Receiver type 'Person' for instance message is a forward


#1

I’ve entered the code starting on Page 153 and I get the error "Receiver type ‘Person’ for instance message is a forward declaration. On each of the lines I have shown below in red.

What is a forward declaration and have I missed something that might cause this error? How do I track down this error and fix it?

-(void)startObservingPerson:(Person *)person{
[color=#FF0000] [person addObserver:self[/color]
forKeyPath:@"personName"
options:NSKeyValueObservingOptionOld
context:&RMDocumentKVOContext];

[color=#FF0000] [person addObserver:self[/color]
forKeyPath:@"expectedRaise"
options:NSKeyValueObservingOptionOld
context:&RMDocumentKVOContext];
}
-(void)stopObservingPerson:(Person *)person{
[color=#FF0000] [person removeObserver:self[/color]
forKeyPath:@"personName"
context:&RMDocumentKVOContext];
[color=#FF0000] [person removeObserver:self[/color]
forKeypath:@“expectedRaise”]
context:&RMDocumentKVOContext];
}


#2

My guess is that you have not imported Person.h at the top of the .m file (p.151).

We created a forward declaration of Person with “@class Person;” in the .h file. So the compiler is telling you, “You told me this Person class exists, but in order to do anything more with it at this point I need to see the actual @interface.” Thus importing Person.h will resolve it. The forward declaration is fine as long as you are just dealing with the type, but once you try to call a method on that type, it needs the full class definition from the header file.

Adam


#3

I was missing the #import "Person.h"
also I had some typo in one of the lines that I could not see. I retyped the line and the error cleared.