PDA

View Full Version : Protocol of delegate or source class, which is defined first ?




namanhams
Jun 18, 2009, 11:15 PM
Hi everyone,

I've used delegate many times, but i've just realized something that i dont know why it can be like that.
Let say a class A has a delegate which implements a protocol B.

- Class A :
@interface A : NSObject {
id<B> delegate;
}
@end

- Protocol B :
@protocol B
- object : (A *) a doSomething : (SomeClass *) s
@end

Because A references B, B references A, I dont know how can i define both things. I know it's possible (the UITableView and UITableViewDelegate is an example), but i dont know how. I've tried to go arround this problem but the compiler keeps giving me errors.

Thanks for reading my post.



kainjow
Jun 18, 2009, 11:43 PM
Before the @interface on your class, put @protocol B; - this just makes the compiler aware of the protocol at that point, similar to how you can use @class.

namanhams
Jun 19, 2009, 04:18 AM
I know about @class, but i dont know that we can use @protocol the same way.

Thanks a lot.