objective c - iPhone Obj-C: Anonymous Category or "private" Category? -
To declare private methods
Style-wise (and functionally, if there is any difference), which of these its better?
@interface MyClass () @interface MyClass (private)
Two syntax serve different purposes.
An Enrolled Category - @ Interface Fu (FooCategory) - It's usually used:
(1) Extending an existing class by adding functionality . Example: NSAttributedString in the Foundation is enhanced by a category in the appet, which adds AppKit specific RTF-like text formatting API.
(2) Declare a set of methods to implement or not by a representative. Example: Various classes declare - but do not implement - @interface nsobject (setodelegate method).
Form (2) is now favored that @protocol @optional methods have been extended to support Object-C 2.0.
A class extension - @interface Foo () - You are designed to allow additional personal APIs - SPI or System Programming Interface - It is commonly used to implement interiors. It usually appears at the top of the .m file. Any method / properties declared in class extensions should be implemented in the implementation @, just like the methods / properties found in public @interfaces.
Synthesizeing @extors to read the class extensions as publicly read as a publicly read @ property.
Example:
Foo.h
@interface Foo: NSObject @property (read-only, copying) NSString * times; - (zero) public relations; @end
Foo.m
@interface Foo () @ Property (text, copy) NSString * times; - (zero) supercancet international sounding; @end @implementation Foo @ synthesis bar; ... two methods must be implemented or the compiler will warn .... @end
Comments
Post a Comment