title: Is it ever Ok to have a 'strong' reference for a delegate?
body: <p>I have a class that retrieves JSON from a URL and returns the data via the protocol/delegate pattern.</p>
  
  <p><em>MRDelegateClass.h</em></p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  
  @protocol MRDelegateClassProtocol
  @optional
  - (void)dataRetrieved:(NSDictionary *)json;
  - (void)dataFailed:(NSError *)error;
  @end
  
  @interface MRDelegateClass : NSObject
  @property (strong) id &lt;MRDelegateClassProtocol&gt; delegate;
  
  - (void)getJSONData;
  @end
  </code></pre>
  
  <p>Note that I'm using <code>strong</code> for my delegate property.  More about that later...</p>
  
  <p>I am trying to write a 'wrapper' class that implements getJSONData in a block-based format.</p>
  
  <p><em>MRBlockWrapperClassForDelegate.h</em></p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  
  typedef void(^SuccessBlock)(NSDictionary *json);
  typedef void(^ErrorBlock)(NSError *error);
  
  @interface MRBlockWrapperClassForDelegate : NSObject
  + (void)getJSONWithSuccess:(SuccessBlock)success orError:(ErrorBlock)error;
  @end
  </code></pre>
  
  <p><em>MRBlockWrapperClassForDelegate.m</em></p>
  
  <pre><code>#import "MRBlockWrapperClassForDelegate.h"
  #import "MRDelegateClass.h"
  
  @interface DelegateBlock:NSObject &lt;MRDelegateClassProtocol&gt;
  @property (nonatomic, copy) SuccessBlock successBlock;
  @property (nonatomic, copy) ErrorBlock errorBlock;
  @end
  
  @implementation DelegateBlock
  - (id)initWithSuccessBlock:(SuccessBlock)aSuccessBlock andErrorBlock:(ErrorBlock)aErrorBlock {
      self = [super init];
      if (self) {
          _successBlock = aSuccessBlock;
          _errorBlock = aErrorBlock;
      }
      return self;
  }
  
  #pragma mark - &lt;MRDelegateClass&gt; protocols
  - (void)dataRetrieved:(NSDictionary *)json {
      self.successBlock(json);
  }
  - (void)dataFailed:(NSError *)error {
      self.errorBlock(error);
  }
  @end
  
  // main class
  @interface MRBlockWrapperClassForDelegate()
  @end
  
  @implementation MRBlockWrapperClassForDelegate
  
  + (void)getJSONWithSuccess:(SuccessBlock)success orError:(ErrorBlock)error {
      MRDelegateClass *delegateClassInstance = [MRDelegateClass new];
      DelegateBlock *delegateBlock = [[DelegateBlock alloc] initWithSuccessBlock:success andErrorBlock:error];
      delegateClassInstance.delegate = delegateBlock; // set the delegate as the new delegate block
      [delegateClassInstance getJSONData];
  }
  
  @end
  </code></pre>
  
  <p>I've come to the objective-c world relatively recently (only lived in ARC times, and still coming to terms with blocks) and admittedly my understanding of memory management is on the slimmer side of things.</p>
  
  <p>This code seems to work fine, but only if I have my delegate as <code>strong</code>.  I understand that my delegate should be <code>weak</code> to avoid potential retain-cycles.  Looking in instruments, I find that allocations do not continue to grow with continued calls.  However, I believe 'best practice' is to have <code>weak</code> delegates.</p>
  
  <p><em>Questions</em></p>
  
  <p>Q1) is it ever 'ok' to have <code>strong</code> delegates</p>
  
  <p>Q2) how could I implement the block-based wrapper leaving the delegate of the underlying class  as <code>weak</code> delegate (ie. prevent the *delegateBlock from being deallocated before it receives the protocol methods)?</p>