0
@class  GSValue;
@interface GSValue : NSObject   // Help the compiler
@end
@class  GSNonretainedObjectValue;
@interface GSNonretainedObjectValue : NSObject  // Help the compiler
@end

the above code from NSValue.m . i google and giving me some info, it indicate that @class(not accompanying with @interface) used for class forward declaration between two classes,but only declared as a pointer of the class. my question is why "@class GSValue;" immediately followed by "@interface GSValue:NSObject",what's the meaning?

hao haochao
  • 91
  • 1
  • 8

1 Answers1

0

I'm not quite sure, but i think in this case it's forward declaration + declaration, that GSValueand other classes are subclasses of NSObject. So, compiler won't give a warning when you write [GSValue class]. It's not actually "help", it's just to get rid of warnings.

Though, if this is the case then I don't know why they use forward declaration with @interface, cause it works just the same without @class directive.

I see it that way.

They used forward declaration in the first place. Then they noticed that compiler gives warnings Receiver 'GSValue' is a forward class and corresponding @interface may not exist, so they added @interface sections, but forgot or didn't bother to delete former @class directives.

Alexander N.
  • 564
  • 3
  • 10
  • hi @Alexander N. i 'm using objective-c on GNUSTEP. i delete the whole "@interface" and leaving "@class". it's no warning come out of compiler. – hao haochao Jan 16 '13 at 17:31
  • Well, that's a shame. There _should_ be a warning, 'cause compiler does not know if an undeclared class has any methods (like `class`). – Alexander N. Jan 16 '13 at 17:36