AndrewShmig
AndrewShmig

Reputation: 4923

Why I am getting an error while forward declaring root class in Objective-C?

Example:

@class MyRootObject;

@interface MyObject : MyRootObject
@end

Getting form XCode:

Class MyObject defined without specifying a base class.

MyRootObject class is:

@interface MyRootObject : NSObject

- (id)init;

@end

@implementation MyRootObject

- (id)init
{
   self = [super init];

   if(self){
      // some code here
   }

   return self;
}

@end

Upvotes: 1

Views: 541

Answers (1)

Lily Ballard
Lily Ballard

Reputation: 185831

You can't inherit from a forward-declared class. You need to #include the appropriate header instead.

Upvotes: 5

Related Questions