Strange inheritance behaviour in Objective-C
- by Smikey
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