开发者

How to declare protocol in separate header file

开发者 https://www.devze.com 2023-03-21 18:16 出处:网络
I have two classes. Both these classes are delegates of each other. This gives me error like \"Can not f开发者_开发百科ind protocol declaration\". After searching on net, I came to the conclusion that

I have two classes. Both these classes are delegates of each other. This gives me error like "Can not f开发者_开发百科ind 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?


I have a example for you..

@class ClassA;
@class ClassAController;

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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消