info: iOS5, xcode4.3.2, iphone5
Create tab view controller application from xcode template wizard.
Following code gets generated (some truncated by me for this post).
=== SUFirstViewController.h
#import <UIKit/UIKit.h>
@interface SUFirstViewController : UIViewController
@end
=== SUFirstViewController.m
#import "SUFirstViewController.h"
@interface SUFirstViewController ()
@end
@implementation SUFirstViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
@end
===
My question is regarding this code snippet:
@interface SUFirstViewController ()
@end
Why is this particular code snippet generated in the SUFirstViewController.m ?
Can I remove it ?
How do I use it ?
As Matthias said, is for things you want to keep private or hidden to clients of the class 🙂
This part of the code is called class extension (others call them anonymous categories because they don’t have a name in the parenthesis) and you could used them to write something like this:
Interface Builder is pretty smart and you will be able to hock your outlets/actions if you write them here, in fact Apple recommends to have your IBOutlets/IBActions declared in this place because most of the time you don’t need to expose them.
You can also have any other private property, and method like the ones I wrote.
Hope it helps.