Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I just happened to see this post while researching. Here is a sample code:</p> <p>ClassA.h file:</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import "ClassB.h" @interface ClassA : NSObject &lt;ClassBDelegate&gt; @end </code></pre> <p>ClassA.m file:</p> <pre><code>#import "ClassA.h" @implementation ClassA -(void)createAnInstanceOfClassB { ClassB *myClassB = [[ClassB alloc]init]; //create an instance of ClassB myClassB.delegate = self; //set self as the delegate // [myClassB optionalClassBMethod]; //this is optional to your question. If you also want ClassA to call method from ClassB } -(void)calculate { NSLog(@"Do calculate thing!"); // calculate can be called from ClassB or ClassA } @end </code></pre> <p>ClassB.h file:</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @protocol ClassBDelegate &lt;NSObject&gt; -(void)calculate; //method from ClassA @end @interface ClassB : NSObject @property (assign) id &lt;ClassBDelegate&gt; delegate; //-(void)optionalClassBMethod; //this is optional to your question. If you also want ClassA to call method from ClassB @end </code></pre> <p>ClassB.m file:</p> <pre><code>#import "ClassB.h" @implementation ClassB @synthesize delegate; -(void)whateverMethod { [self.delegate calculate]; // calling method "calculate" on ClassA } //-(void)optionalClassBMethod //this is optional to your question. If you also want ClassA to call method from ClassB //{ // NSLog(@"optionalClassBMethod"); // [self whateverMethod]; //} @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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