最近我最近下載了最新版本的XCode(4.3.1)。我注意到,當我創建新的UIViewController
對象時,關聯的.m
文件包含我以前從未見過的其他類定義代碼。從XCode 4.2到4.3,新的ViewController類.m文件的定義不同。爲什麼?
具體而言,如果我創建一個名爲'TestViewController'的新UIViewController
,我會得到以下.m
文件輸出。
\\... removed comments...
#import "TestViewController.h"
@interface TestViewController()
@end
@implementation TestViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
\等等
新加入的代碼,因爲的XCode 4.3是#import
聲明中所說的部分:
@interface TestViewController()
@end
什麼用這樣的代碼?可以/應該在括號內進行任何操作嗎?是否有任何代碼在@interface
和@end
聲明中出現?
簡而言之,將此代碼添加到模板有什麼意義?作爲一個有趣的方面說明,當我嘗試從模板創建NSObject
時,上述代碼片段未被添加。它可能會與其他類型的模板一起出現,但目前我只遇到了UIViewController
和UITableViewController
對象。
你也可以做其他方便的事情,比如私下遵守協議而不公開這些信息 – Sean 2012-03-21 19:21:32