0

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?

4

1 回答 1

1

您可以通过预编译步骤来做到这一点:

a) 在项目中为每个 buildTarget 创建一个 #def 值,如 version( #define VERSION 1.0)。每个 buildTarget 都应该有一个不同的版本,并且代表你的固件的不同版本。为此,请转到项目选项,构建目标选项-> 构建设置-> 预编译器宏

b) 创建一个预编译器函数,例如 GREATER THAN: #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) v>= VERSION(可以在 .pch 中定义)

c) 在标题处

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

ETC

你认为这能解决你的问题吗。

如果你这样做,预编译器将跳转他的版本下的代码

于 2012-12-19T16:10:18.763 回答