title: Obj-C, How do I use a category to supply methods which I will use in delegate methods?
body: <p>I want to provide methods used in several view controllers called in my delegate methods.</p>
  
  <p>For example, I have some CloudKit functionality (I've added this to my own framework, but I don't think thats important), where I want to provide some crash logging.
  Previosuly I had a crashLog function in each of my view controllers, which worked fine, but I have a lot of duplicate code.</p>
  
  <p>Therefore I'd like to produce a category with these methods instead.</p>
  
  <p>However I'm having difficulty getting my delegate methods to see these category methods.</p>
  
  <p>Here's my code..</p>
  
  <p>UIViewController+CloudKitDelegates.h</p>
  
  <pre><code>@interface UIViewController (CloudKitDelegates) &lt;iCloudDBDelegate&gt;
  
  @property (weak,nonatomic) id&lt;iCloudDBDelegate&gt;iCloudDBDelegate;
  
  -(void)crashLog:(NSString*)message, ...;
  
  @end
  </code></pre>
  
  <p>UIViewController+CloudKitDelegates.m</p>
  
  <pre><code>#import "UIViewController+CloudKitDelegates.h"
  
  @implementation UIViewController (CloudKitDelegates)
  @dynamic iCloudDBDelegate;
  
  -(void)crashLog:(NSString*)message, ...
  {
      va_list args;
      va_start(args, message);
  
      NSLog(@"%@", [[NSString alloc] initWithFormat:message arguments:args]);
  
      va_end(args);
  }
  
  @end
  </code></pre>
  
  <p>h file - my calling view controller (e.g. My View Controller)</p>
  
  <pre><code>#import "UIViewController+CloudKitDelegates.h"
  </code></pre>
  
  <p>m file - delegate method</p>
  
  <pre><code>-(NSString*)getDBPath
  {
      [self.iCloudDBDelegate crashLog: @"testing"];
  </code></pre>
  
  <p>From this call I'm getting an error ...</p>
  
  <pre><code>'NSInvalidArgumentException', reason: '-[MyViewController crashLog:]: 
      unrecognized selector sent to instance
  </code></pre>
  
  <p>The error is showing that my calling view controller called MyViewController doesn't have the crashLog method, which I have in my category.</p>
  
  <p>Any ideas where I'm going wrong ?</p>