views:

66

answers:

1

I have:

@interface A
@property (nonatomic, retain) B *toB;
@end

@interface B
@property (nonatomic, retain) A *toA;
@end

This causes the compiler to give me this:

error: expected specifier-qualifier-list before 'Property'

Now, it appears this has something to do with the order of parsing the files as independently, they work as long as the pointed to object is declared first.

How can I get round this?

+2  A: 

Use forward declaration via @class to let the compiler know there is a class named A that it hasn't seen the interface for yet.

For example:

@class A;
@class B;

@interface A
@property (nonatomic, retain) B *toB;
@end

@interface B
@property (nonatomic, retain) A *toA;
@end
Jim Correia
No need to forward-declare A here, just B. A has already been declared by the time it's used in B's declaration.
smorgan
Thanks, I had i feeling that it would be something like that :-)
pingbat