Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'll need to split your methods in to different "categories," which each get their own h and m files. You'll also need an h and m file for the class itself. Here's a simple little example that I think will show you what you need to do.</p> <p>TestClass.h</p> <pre><code>#import &lt;Cocoa/Cocoa.h&gt; @interface TestClass : NSObject { } @end </code></pre> <p>TestClass.m</p> <pre><code>#import "TestClass.h" @implementation TestClass @end </code></pre> <p>TestClass+Category1.h</p> <pre><code>#import &lt;Cocoa/Cocoa.h&gt; #import "TestClass.h" @interface TestClass(Category1) -(void)TestMethod1; @end </code></pre> <p>TestClass+Category1.m</p> <pre><code>#import "TestClass+Category1.h" @implementation TestClass(Category1) -(void)TestMethod1 { NSLog(@"This is the output from TestMethod1"); } @end </code></pre> <p>TestClass+Category2.h</p> <pre><code>#import &lt;Cocoa/Cocoa.h&gt; #import "TestClass.h" @interface TestClass(Category2) -(void)TestMethod2; @end </code></pre> <p>TestClass+Category2.m</p> <pre><code>#import "TestClass+Category2.h" @implementation TestClass(Category2) -(void)TestMethod2 { NSLog(@"This is the output from TestMethod2"); } @end </code></pre> <p>Then in whatever file is using your class, you'll use</p> <pre><code>#import "TestClass.h" #import "TestClass+Category1.h" #import "TestClass+Category2.h" </code></pre> <p>Now you can create an instance of class TestClass and it will have all the methods from both category1 and category2. Simply use</p> <pre><code>TestClass* test = [[TestClass alloc] init]; [test TestMethod1]; [test TestMethod2]; </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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