Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The two syntaxes serve different purposes.</p> <p>A named category -- <strong>@interface Foo(FooCategory)</strong> -- is generally used to:</p> <p>(1) extend an existing class by adding functionality. Example: NSAttributedString in Foundation is extended by a category in AppKit that adds AppKit specific RTF-like text formatting API.</p> <p>(2) declare a set of methods that might or might not be implemented by a delegate. Example: Various classes declare -- but don't implement -- @interface NSObject(SetODelegateMethods).</p> <p>Form (2) has fallen out of favor now that @protocol has been extended to support @optional methods in Objective-C 2.0.</p> <p>A class extension -- <strong>@interface Foo()</strong> -- is designed to allow you to declare additional private API -- SPI or System Programming Interface -- that is used to implement the class innards. This typically appears at the top of the .m file. Any methods / properties declared in the class extension must be implemented in the @implementation, just like the methods/properties found in the public @interface.</p> <p>Class extensions can also be used to redeclare a publicly readonly @property as readwrite prior to @synthesize'ing the accessors.</p> <p>Example:</p> <p>Foo.h</p> <pre><code>@interface Foo:NSObject @property(readonly, copy) NSString *bar; -(void) publicSaucing; @end </code></pre> <p>Foo.m</p> <pre><code>@interface Foo() @property(readwrite, copy) NSString *bar; - (void) superSecretInternalSaucing; @end @implementation Foo @synthesize bar; .... must implement the two methods or compiler will warn .... @end </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