Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You will want to declare a delegate protocol for your class. An example of a delegate protocol and interface for class <code>Foo</code> might look like this:</p> <pre><code>@class Foo; @protocol FooDelegate &lt;NSObject&gt; @optional - (BOOL)foo:(Foo *)foo willDoSomethingAnimated:(BOOL)flag; - (void)foo:(Foo *)foo didDoSomethingAnimated:(BOOL)flag; @end @interface Foo : NSObject { NSString *bar; id &lt;FooDelegate&gt; delegate; } @property (nonatomic, retain) NSString *bar; @property (nonatomic, assign) id &lt;FooDelegate&gt; delegate; - (void)someAction; @end </code></pre> <p>Don't forget to synthesize your properties in the <code>@implementation</code>.</p> <p>What this code did was declare a protocol called FooDelegate; a class that conforms to this protocol would be declared like <code>@interface SomeClass : SuperClass &lt;FooDelegate&gt; {}</code>. Because this class conforms to the protocol <code>FooDelegate</code>, it now gets to implement the methods under <code>FooDelegate</code> (to require that these be implemented, use <code>@required</code> instead of <code>@optional</code>). The last step is for a <code>Foo</code> object to be instantiated in the class that conforms to <code>FooDelegate</code>, and for this <code>Foo</code> object to have its delegate property set:</p> <pre><code>Foo *obj = [[Foo alloc] init]; [obj setDelegate:self]; </code></pre> <p>Now, your class is prepared to receive messages from <code>Foo</code> objects that have their delegates set correctly.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload