我已經使用.m中的類擴展作爲具有「私有」方法和變量的方法。我讀過自Xcode 4.4以來,編譯器不再需要聲明的私有方法。何時聲明類擴展方法
例如,這甚至會編譯儘管helperMethodC未聲明:
在.H
@interface MyClass : NSObject
-(void)publicMethodA;
@end
在.M
@interface MyClass()
- (void) pseudoPrivateMethodB;
@end
@implementation MyClass
- (void)publicMethodA
{
//Do Something
}
- (void)pseudoPrivateMethodB
{
[self helperMethodC];
}
- (void) helperMethodC
{
// Do something
}
雖然私有方法不再需要聲明爲編譯(helperMethodC),是否有一個樣式指南,歷史原因或所有私有方法(即helperMethodC)仍應聲明的規則?或者什麼時候聲明和不聲明私有方法的「規則」?
僅供參考 - 除非您有循環依賴,否則它們從不需要。您可以通過將您的方法排除在不需要私人聲明的順序上來避免它們。換句話說,如果將'helperMethodC'放在'pseudoPrivateMethodB'之前,您發佈的代碼將始終編譯。 – rmaddy