title: Objective-C calling a delegate method from a class where the delegate method resides within another class
body: <p>If I have a delegate which resides within its own header file myDelegate.h. Then I have a class (ClassOne) that implements the delegate protocol (therefore implementing the delegate function(s)). Then I create another class (ClassTwo) that has a instance variable of myDelegate. Can I then use this variable to call the function that resides in ClassOne?</p>
  
  <p>Here is the code:</p>
  
  <pre><code>//myDelegate.h
  @protocol myDelegate &lt;NSObject&gt;
  
  - (BOOL)myFunction:(NSString*)sString;
  
  @end
  
  
  //ClassOne.h
  @interface ClassOne : NSObject &lt;myDelegate&gt; {
  
  }
  
  - (BOOL)myFunction:(NSString*)sString;
  
  @end
  
  //ClassOne.m
  #import "ClassOne.h"
  @implementation ClassOne
  
  - (BOOL)myFunction:(NSString*)sString
  {
      //do stuff
  }
  
  @end
  
  
  //ClassTwo.h
  #import "myDelegate.h"
  @interface ClassTwo : NSObject {
      id&lt;myDelegate&gt; del;
  }
  
  @property (nonatomic, retain) id&lt;myDelegate&gt; del;
  
  @end
  
  //ClassTwo.m
  #import "ClassTwo.h"
  @implementation ClassTwo
  
  - (void)aFunction:(NSString*)string
  {
      [del myFunction:string];
  }
  
  @end
  </code></pre>