Sorry for my English, let speak from my heart :) In one project which I work, I noticed an interesting moment.
In *.h file declared interface:
@interface FrontViewController : UIViewController
...
@end
And in *.m file I found another interface.
@interface FrontViewController()
// Private Properties:
@property (retain, nonatomic) UIPanGestureRecognizer *navigationBarPanGestureRecognizer;
// Private Methods:
- (IBAction)pushExample:(id)sender;
@end
@implementation FrontViewController
...
@end
Why is it needed? And what's the point? -I think that this is for convenience. Yes?
That's a class extension. It's usually used to declare private methods and properties for a class.
Read about it here.
That is a class extension. It allows you to declare "private" methods and properties for a class, even if you don't have access to the source. The primary use is to not expose those methods as part of the interface. Unlike most languages, these methods are run-time discoverable, so the value of these is in the IDE auto-completion, not in preventing consumers of your class from calling the hidden methods, which is why I put private in quotes. It is possible to simply define methods in the implementation without a declaration, but then they must be implemented above any places they are used. Declaring them as an extension prevents this problem.
If an extension is named, then it becomes a category which can be used to distribute your class implementation among several files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With