title: Implementing objc protocol methods in a separate .m file from the main class?
body: <p>I'm trying to separate the methods for the NSCoding into separate files from my actual classes.  I know you can generally define new methods using Categories in Objective-C, but it seems Xcode still sends warnings when it doesn't encounter the -encodeWithCoder: and -initWithCoder: methods in the master class file.</p>
  
  <p>The reason I'm doing this (and hopefully this doesn't sound too convoluted) is that I have many dozen classes spread across various files, and in order to avoid the tedium and redundancy of writing out encodeWithCoder:/initWithCoder: methods for each and every class, I put together a small script to automatically parse the header files and generate the necessary encoding/decoding code based on variable types and dump the results into a single Encoders.m.  The result links properly, but I still receive the warnings during compilation "Incomplete implementation of class 'MyClass'", "Method definition for '-initWithCoder:' not found" (etc), and "Class 'MyClass' does not fully implement the 'NSCoding' protocol".  I've tried simply adding the declarations to the classes' .h files, but no go.</p>
  
  <p>Is there any way to inform Xcode that the methods are in fact implemented, just not in the non-Category class file?</p>
  
  <p>A simplified example:</p>
  
  <p><em>MyClass.h</em></p>
  
  <pre><code>@interface MyClass : NSObject &lt;NSCoding&gt; {
      int num;              //@ENCODABLE
      float timer;          //@ENCODABLE
      SomeOtherClass *obj;  //@ENCODABLE
  }
  ...
  @end
  </code></pre>
  
  <p><em>MyClass.m</em></p>
  
  <pre><code>#import "MyClass.h"
  @implementation MyClass
  ...
  @end
  </code></pre>
  
  <p><em>Encoders.m</em></p>
  
  <pre><code>#import "MyClass.h"
  @implementation MyClass (Encoding)
  -(void) encodeWithCoder:(NSCoder*)encoder {
      // Auto-generated encoding of instance variables
  }
  -(id) initWithCoder:(NSCoder*)decoder {
      if (self = [self init]) {
          // Auto-generated decoding of instance-variables
      }
      return self;
  }
  @end
  </code></pre>