Harsh
Harsh

Reputation: 666

How to declare protocol in separate header file

I have two classes. Both these classes are delegates of each other. This gives me error like "Can not find protocol declaration". After searching on net, I came to the conclusion that, this is the case of cyclic dependency.

To break this dependency the solution they have suggested is to define protocol in another header file. I could not find any tutorial on how to do this and how will it affect my code?

Upvotes: 0

Views: 2821

Answers (3)

iCoder4777
iCoder4777

Reputation: 1692

I have a example for you..

@class ClassA;
@class ClassAController;

@protocol CreateClassADelegate
-(void)CreateClassA:(ClassAController *)sender didCreateClassA:(ClassA *)ClassAObj;
-(void)CreateClassACancel:(TSInputController *)sender;
@end

Upvotes: 2

Ariel
Ariel

Reputation: 2440

In case you are using XCode 4 you just creating new file as always, the difference is that you need to choose Objective-C protocol in Cocoa Touch section rather then Objective-C class or UIViewController subclass.
Other approach you may use is to create new Objective-C class and then just delete the .m file manualy and change @interface to @protocol in .h file.

Upvotes: 0

visakh7
visakh7

Reputation: 26400

Check @Toro's answer in this previous SO question UIViewController calling each other's delegate

Upvotes: 0

Related Questions