Search code examples
objective-cinheritancegnustep

Objective-C on GNUStep: Accessing ivars of the parent class


I'm pretty new to Objective-C. Most of my experience is in Java. I have a base class:

@interface Bug : NSObject <BugProtocol> {

    @private
    World* world;
    NSString* name;
    NSString* layer;
    long x;
    long y;
    BOOL alive;

...
...


}

...
...

@end

and a class that extends this base class:

@interface RandomBug : Bug
    ...
    ...
@end

However, when I try to access properties that I've defined in the parent class, the compiler complains that it cannot find them. Most of the examples I've seen for access properties is tailored towards OS X (i.e., using things like @property which, as far as I know, is not fully supported in GNUStep).


Solution

  • I figured it out. I just need to use @protected (just like in Java):

    @interface Bug : NSObject <BugProtocol> {
    
        @protected
        World* world;
        NSString* name;
        NSString* layer;
        long x;
        long y;
        BOOL alive;
    
    ...
    ...
    
    
    }
    
    ...
    ...
    
    @end