What I’d like to do is separate a category’s methods into private and public methods. The private methods need to be visible outside of that category’s file, but not outside the class.
For instance, let’s say I have the following files:
ClassA.m
ClassA.h // <-- Includes definitions of public category methods
ClassAPrivates.h // <-- Includes definition of private category methods.
ClassA+Render.m
ClassAPrivates.h would look like this:
@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
And ‘ClassA.h’ would look like this:
@interface ClassA : NSObject
// public methods of ClassA
@end
@interface ClassA (Render)
// public methods of category Render
-(void)drawLine;
-(void)drawCircle;
@end
However, XCode complains about duplicate interface for Render. Any workarounds?
No need to create separate categories for private methods.
There are 3 scenarios:
ClassA+Render.maccessing the private methods that are defined in theClassA.mClassA.maccessing the private methods that are defined inClassA+Render.mClassA+Render.maccessing the properties defined inClassA.mNote: Though the original poster hasn’t asked for Scenario 3, I thought it might come in handy
Example
ClassA.mdefines 2 private methodsbasePrivateMethod1– This would invokerenderPrivateMethod1basePrivateMethod2ClassA+Render.mdefines 2 private methodsrenderPrivateMethod1renderPrivateMethod2– This would invokebasePrivateMethod2Scenario 1
ClassA+Render.mjust create an extension and forward declare the methods that you want to use.ClassA+Render.m
Scenario 2
ClassA+Render.hjust declare the methods defined inClassA+Render.m.ClassA.mjust include (#import)ClassA+Render.hClassA+Render.hwould / should not be used outside ofClassAClassA+Render.h
Scenario 3
ClassA+PropertiesClassA+Properties.hredeclare all the propertiesClassA+Properties.muse@dynamicfor all the properties to tell the compiler that the actual definition of these properties is else whereClassA+Render.minclude (#import)ClassA+Properties.h, so that all the properties are accessibleClassA+Properties.h
ClassA+Properties.m