Protocol of delegate or source class, which is defined first ?

Discussion in 'iOS Programming' started by namanhams, Jun 18, 2009.

  1. namanhams macrumors regular

    Jun 3, 2009
    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;

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

    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.
  2. kainjow Moderator emeritus


    Jun 15, 2000
    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.
  3. namanhams thread starter macrumors regular

    Jun 3, 2009
    I know about @class, but i dont know that we can use @protocol the same way.

    Thanks a lot.

Share This Page