我刚刚开始编写Objective-C编程,并且具有Java背景,想知道编写Objective-C程序的人如何处理私有方法.
我理解可能存在一些惯例和习惯,并将此问题视为人们在Objective-C中使用私有方法的最佳技术的聚合器.
请在发布时为您的方法添加一个参数.它为什么好?它有哪些缺点(你知道)以及你如何处理它们?
至于到目前为止我的发现.
可以使用MyClass.m文件中定义的类别 [例如MyClass(Private)]来对私有方法进行分组.
这种方法有两个问题:
第一个问题可以解决空类 [例如MyClass()].
第二个困扰我很多.我希望在文件末尾附近实现(和定义)私有方法; 我不知道这是否可能.
我头上有很多问号.我没有得到的是在xcode 4.3之前我需要在我的实现文件中声明前向声明(对于私有方法).
就像我的.m文件一样:
// deleting this with xcode 4.3 the below code still does work
// in previous versions i had to put this because otherwise the compiler can't find methodFirst
@interface DetailViewController ()
- (void)methodFirst;
- (void)methodSecond;
@end
@implementation DetailViewController
- (void) methodSecond
{
// if i delete the forward declaration now adays i dont get a compiler error that he cant find method first
[self methodFirst];
}
- (void) methodFirst
{
}
@end
Run Code Online (Sandbox Code Playgroud)
现在看来我不再需要那样做了?Apple是否更新了编译器以便不再需要提交声明?
我找不到任何有关此更改的Apple官方消息来源的参考.我想知道其他人在新环境中遇到了什么.