title: How to create a delegator in objective C?
body: <p>I am trying to learn, how to implement delegation pattern in objective C. But the discussion almost exclusively concentrates on the <strong>adoption</strong> of protocols and then <strong>implementing the delegate methods</strong> that come with particular protocol - or - the delegation principle alone - or protocols alone.   </p>
  
  <p>What I am unable to find, is a easy to understand material about how to write a class that will serve as a delegator. By that I mean the class, which the message of some event will come from and which will provide the protocol for receiving that message - kind of 2in1 description. (protocols and delegation). </p>
  
  <p>For the purpose of my learning, I'd like to go along the following trivial example, using an iPhone, a Cocoa touch application and Xcode4.2, using ARC, no Storyboard or NIBs.</p>
  
  <p>Let's have a class with name "Delegator", which is a subclass of NSObject. The Delegator class has NSString instance variable named "report" and adopts the UIAccelerometerDelegate protocol.In the Delegator implementation, I will implement the the delegate method </p>
  
  <pre><code>-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration 
  </code></pre>
  
  <p>This delegate method will create a NSString  @"myReport" and store it in the report variable anytime there is an accelerometer event. Further, I want to have a second class named ReportsStorage (a subclass of NSobject), which can store some Nsstring (report) in its instance variable called latestReport.
  So far so good. 
  Now lets get back to theDelegator Class. I'd like to implement a protocol in Delegator named ReportsDelegate which will notify the class that adopts it (the ReportsStorage class), that a report was generated and will pass this report through the delegate method, which should be (I believe) something like this</p>
  
  <pre><code>-(void)delegator:(Delegator *)delegator didCreateNewReport:(NSString *)report;
  </code></pre>
  
  <p>Can you please provide the code for Delegator Class (incl. the "delegate" property), that will achieve this, with a description what each line of code means?   </p>
  
  <p>Thanks in advance, EarlGrey </p>