iPhone静态库: How to hide instance variable

标签 iphone objective-c static-libraries private-members

我正在创建一个静态库以使用以下指南进行共享: http://www.amateurinmotion.com/articles/2009/02/08/creating-a-static-library-for-iphone.html

在其中一个函数中,我返回一个“SomeUIView”,它是 UIView 的子类,并在公共(public) header 中定义,但是我不想在公共(public) header 中公开 SomeUIView 的内部实例变量。

我尝试使用 SomeUIView 的私有(private)内部头文件的类别,但我不断遇到“类‘SomeUIView’的重复接口(interface)声明”。

有人知道怎么做吗?

谢谢!

最佳答案

类别和扩展不能向类添加实例变量。我会在这里使用 PIMPL 习惯用法 - 使用私有(private)实现对象:

// header
@class MyObjImpl;
@interface MyObj {
    MyObjImpl* impl;
}
@end

// implementation file:
@interface MyObjImpl {
    id someIvar;
}
// ...
@end

// ... etc.

这还可以使您的公共(public)界面保持稳定,以防您想添加一些内容供内部使用。

“重复接口(interface)”来自第二个接口(interface)声明中缺少的括号:

// header:
@interface MyObj 
// ...
@end

// implementation file:
@interface MyObj () // note the parentheses which make it a class extension
// ...
@end

关于iPhone静态库: How to hide instance variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2909392/

相关文章:

c++ - 如何处理静态库中不包含在任何 .cpp 中的 .hpp

swift - 在 swift 中使用静态 C 库,找不到模块

iphone - UIInterface方向问题

iphone - 在 iOS 上的 UIWebView 中观看 Vimeo 视频

ios - 我如何在 Swift 中使用 CFArrayRef?

objective-c - Uitableview 单元格重复?

c++ - 无法编译,错误 : cryptlib. h:没有那个文件或目录

ios - APNS Tester 推送通知失败

iphone - 如何在iPhone中进行中文语音识别

objective-c - 从字符串解析数字时如何限制小数位数?