4

我正在尝试编写一个objective-c 框架,并且我希望方法和属性仅在框架内可见。我知道我可以在实现文件内的类扩展中定义它们,但是其他类将无法访问它们。

One way I was thinking to do it was to define a category for example MyClass+Internals and make that header private. but make the MyClass.h header public. I was wondering if there was a better way of doing this. Also, I'm not sure you can define properties within a category I thought it was only methods. Thanks for any suggestions or feedback.

4

1 回答 1

3

假设您有一个名为“Foo”的类,然后在“Foo_Framework.h”中创建:

@interface Foo()
@property ....;
- .... method ....
@end

然后,确保 "Foo_Framework.h "@implementation Foo. 这将导致类 Foo 使用在所述头文件中找到的扩展接口进行编译。然后可以在整个框架中使用该标头。只是不要让它在上述框架之外可用。

您不能在类别中声明属性(合成的)是正确的。这是创建类扩展的主要动机之一,上面就是一个例子。

于 2012-10-24T21:54:06.653 回答