Strange inheritance behaviour in Objective-C

Posted by Smikey on Stack Overflow See other posts from Stack Overflow or by Smikey
Published on 2010-06-02T11:01:33Z Indexed on 2010/06/02 11:03 UTC
Read the original article Hit count: 284

Hi all,

I've created a class called SelectableObject like so:

#define kNumberKey              @"Object"
#define kNameKey                @"Name"
#define kThumbStringKey         @"Thumb"
#define kMainStringKey          @"Main"

#import <Foundation/Foundation.h>

@interface SelectableObject : NSObject <NSCoding> {
    int     number;
    NSString    *name;
    NSString    *thumbString;
    NSString    *mainString;
}

@property (nonatomic, assign) int   number;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *thumbString;
@property (nonatomic, retain) NSString *mainString;

@end

So far so good. And the implementation section conforms to the NSCoding protocol as expected.

HOWEVER, when I add a new class which inherits from this class, i.e.

#import <Foundation/Foundation.h>
#import "SelectableObject.h"

@interface Pet : SelectableObject <NSCoding> {

}

@end

I suddenly get the following compiler error in the Selectable object class!

SelectableObject.h:16: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'interface'

This makes no sense to me. Why is the interface declaration for the SelectableObject class suddenly broken? I also import it in a couple of other classes I've written...

Any help would be very much appreciated. Thanks!

Michael

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about error