Google News
logo
IOS - Interview Questions
What is an unnamed category?
An unnamed category has fallen out of favor now that @protocol has been extended to support the @optional methods. Class Extensions @interface Foo() is designed to allow us to declare additional private API— system programming interface (SPI)—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. Class extensions can also be used to re-declare a publicly read-only @property as read-write prior to doing @synthesize on the accessors.

Example :
Foo.h
@interface Foo:NSObject
@property(readonly, copy) NSString *bar;
-(void) publicSaucing;
@end
Foo.m
@interface Foo()
@property(readwrite, copy) NSString *bar;
- (void) superSecretInternalSaucing;
@end
@implementation Foo
@synthesize bar;
.... must implement the two methods or compiler will warn ....
@end
Advertisement