Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>@interface Foo()</code> creates a class extension (I stand corrected, props to bbum) on interface Foo which is like additional methods added to the interface. Some people also use <code>@interafce Foo(Private)</code> (category) instead of a class extension with <code>()</code>. It's more like "injecting" new methods into a class from outside the class.</p> <p>Placing this in the .m file just keeps other things from "seeing it" in the .h file, but that's it. Basically people normally use categories or class extensions in .m files to specify private interfaces, but they are also used for things like UIKit uses categories to add <code>row</code> and <code>section</code> public methods to NSIndexPath. (This can be confusing.)</p> <p>You don't really need to define private methods this way, but if you have a method called bar that calls method foo before foo is defined in the source file you'll get a compiler warning something like "object self may not respond to foo". You can get rid of that by defining foo before you define bar or any other foo-calling code. It's the same with plain C and functions.</p> <p>Like Ole says this doesn't stop anyone from calling the private methods, it just declares your intention that they be private and causes the compiler to generate the "may not respond to" warnings even if they import the .h file.</p> <p>EDIT</p> <p>Also see <a href="http://www.friday.com/bbum/2009/09/11/class-extensions-explained/" rel="noreferrer">http://www.friday.com/bbum/2009/09/11/class-extensions-explained/</a> for some explanation of categories vs. class extensions. Looks like class extensions should be more correct for defining private methods, from a compiler warning perspective, because category methods are optional. Wish my book would have explained this!</p>
    singulars
    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.
 

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