Search code examples
objective-ciosframeworksprivateencapsulation

Encapsulate properties and methods in framework header files


My goal is to build a framework, but hide some methods and properties from public headers

The point is that framework has everything built in, but different versions must have some properties and methods hidden

I am looking for some method either to delete some marked properties from built headers or to avoid them to be added during the build phase.

In my mind it should be something like this:

@interface MyClass

@property (strong, nonatomic) SomeClass1* instance1;

#AVAILABLE FROM 1.0.2
@property (strong, nonatomic) SomeClass2* instance2;

#AVAILABLE FROM 1.0.3
@property (strong, nonatomic) SomeClass3* instance3;

- (void) method1;

#AVAILABLE FROM 1.0.3
- (void) method2;

@end

So if i set some predefined version value or project version value (doesn't really matter) to 1.0.2
then instance1, instance2 and method1 SHOULD BE in the framework headers, but
instance3 and method2 will be available only in version 1.0.3 or higher

Does anyone know how to do that?


Solution

  • You could do it with the pre-compilation step:

    a) In the project for every buildTarget create a #def value like version(#define VERSION 1.0). Every buildTarget should have a different version and will represent the different versions of your FW. To do that go to the project options, the build target options-> build settings-> PRECOMPILER MACROS

    b) Create a pre-compiler function like GREATER THAN: #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) v>= VERSION (that can be defined in the .pch)

    c) at the headers put

      #if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(1.0.2))
      property (strong, nonatomic) SomeClass2* instance2;
      #endif
    

    etc

    Do you think that solves your problem.

    if you do that the precompiler will jump the code that is under his version