Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You say “I want to avoid making classes and call them.” You need to overcome your <a href="http://c2.com/cgi/wiki?FearOfAddingClasses" rel="noreferrer">fear of adding classes</a>. If you feel the need to split a class's implementation into multiple files, chances are you are trying to do too much in a single class. You need to let that class hand off (“delegate”) some responsibilities to other classes.</p> <p>That said, there are a couple of ways you can split up a class's implementation. The better way, short of fixing your bloated class design, is to use categories or class extensions. You can read all about categories and extensions in <a href="http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/objectivec/chapters/occategories.html" rel="noreferrer"><em>The Objective-C Programming Language</em></a>. Note that the linker will merge the categories and extensions into the class when it creates your executable file, so there's no runtime penalty for using categories or extensions on your own classes.</p> <p>The worse way is to use the C preprocessor's <code>#include</code> directive to paste multiple files together. You can just take some methods out of the implementation file and stick them in new “fragment” file, then <code>#include</code> the fragment file in the implementation file. <strong>Doing this will make it harder to understand your source code.</strong> I would <strong>not</strong> recommend doing this, but here's an example anyway:</p> <h3>MyObject.m</h3> <pre><code>#import "MyObject.h" @implementation MyObject - (void)aMethod { ... } #include "MyObject-moreMethods.m" @end </code></pre> <h3>MyObject-moreMethods.m</h3> <pre><code>// Note: do not include this target in the “Compile Sources” build phase of your target. // And **NO** @implementation statement here! - (void)methodTwo { ... } - (void)methodThree { ... } </code></pre>
 

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