我想要做的是将类别的方法分为私有和公共方法。 私有方法需要在该类别的文件之外可见,但不在课堂之外。目的C同一类别中的私有公共方法
举例来说,假设我有以下文件:
ClassA.m
ClassA.h // <-- Includes definitions of public category methods
ClassAPrivates.h // <-- Includes definition of private category methods.
ClassA+Render.m
ClassAPrivates.h
应该是这样的:
@interface ClassA()
// private methods here, for use inside ClassA
@end
@interface ClassA(Render)
// the private methods of the Render category.
-(void)privateConfigureDeviceContext;
-(void)privateConfigureBufferSpace;
@end
和 'ClassA.h' 应该是这样的:
@interface ClassA : NSObject
// public methods of ClassA
@end
@interface ClassA (Render)
// public methods of category Render
-(void)drawLine;
-(void)drawCircle;
@end
但是,XCode抱怨Render有重复的界面。任何解决方法?
我会老实说,我早就放弃了在iOS上使用Objective-C来支持C++ 11。话虽如此,我已经多次阅读您的解决方案,虽然您可能已经找到了一个解决方案,给出了一个简单的例子,但我不相信它仍然有效,如果有'ClassA + Clear.m'由于多个匿名类别定义('@interface ClassA()'),所以抛出它。 –
我已经在有多个类别的项目中使用过它。 '@interface ClassA()'在.m(多个)文件中使用,并且仅用于重新声明内容,它不重新定义内容。所以,当链接器链接所有的目标文件时,会有一个方法的定义。当您想要在另一个类别中使用一个类别的方法时,只需在想要使用它的类别的.m文件中导入该类别的标题。 – user1046037
您可以像声明或extern变量一样声明任意次数,只会有一个定义(实现),所以没关系。 – user1046037