edie
edie

Reputation: 768

Cannot find protocol declaration in Xcode

I've experienced something today while I'm building my app. I've declared a protocol in my MyObject1 and add delegate property on it. I've assign MyObject2 as a Delegate of the MyObject1. I've added it in this way as usual

@interface MyObject2 : UIViewController <DelegateOfObject1>

But the Xcode says that my the protocol declaration cannot be found. I've check my code but I've declared this protocol. I've try to assign MyObject2 as delegate of other Object. I've edit my code like this

@interface MyObject2 : UIViewController <UITableViewDelegate,DelegateOfObject1>

but Xcode say again that it cannot found declaration of protocol of DelegateOfObject1. I've tried to delete the DelegateOfObject1 on my code and add assign MyObject as delegate of other object and it goes like this.

@interface MyObject2 : UIViewController <UITableViewDelegate,UITabBarDelegate>

No errors have been found. Then I've tried again to add again my DelegateOfObject1 in the code

@interface MyObject2 : UIViewController <UITableViewDelegate,UITabBarDelegate,DelegateOfObject1>

At that time Xcode did not find any error on my code. So I tried again to remove the UITableViewDelegate and UITabBarDelegate on my code.

@interface MyObject2 : UIViewController <DelegateOfObject1>

At that time No error had found but that was the same code I've write before. What should probably the cause of that stuff on my code?

Thanks...

Upvotes: 23

Views: 30427

Answers (5)

Maksim Usenko
Maksim Usenko

Reputation: 311

Use '@class MyObject;' in order to avoid import loop.

Upvotes: 0

Sweta Kishore
Sweta Kishore

Reputation: 51

The error must be in import loop.

I had import "AppDelegate.h" in both the classes.I removed it from the class which declared protocol and the error was gone. :)

Upvotes: 4

Valla
Valla

Reputation: 611

The error is caused due to import loop.

Upvotes: 56

edie
edie

Reputation: 768

I've put my protocol declaration on separate file and import it on MyObject2

Upvotes: 11

djhworld
djhworld

Reputation: 6776

Are you doing an

#import "NameOfDelegate.h" 

At the top of your MyObject header?

Upvotes: 2

Related Questions