问题描述
我认为在 Objective-C 中,我必须将实例变量声明为我的类的接口的一部分,即使这些变量是实现细节并具有私有访问权限.
I gather that in Objective-C I must declare instance variables as part of the interface of my class even if these variables are implementation details and have private access.
在主观"C 中,我可以在我的 .c 文件中声明一个变量,并且它在该编译单元之外不可见.我可以在相应的.h文件中声明它,然后任何在该编译单元中链接的人都可以看到该变量.
In "subjective" C, I can declare a variable in my .c file and it is not visible outside of that compilation unit. I can declare it in the corresponding .h file, and then anyone who links in that compilation unit can see the variable.
我想知道在 Objective-C 中是否有等效的选择,或者我是否确实必须在 .h 中为我的类声明每个 ivar.
I wonder if there is an equivalent choice in Objective-C, or if I must indeed declare every ivar in the .h for my class.
阿里.
推荐答案
Ari,
关于如何完成不可见"实例变量声明的一个很好的参考可以在此处找到 恭敬地给予马特·加拉格尔 (Matt Gallagher).
A good reference to how to accomplish "invisible" instance variable declarations can be found here with credit respectfully given to Matt Gallagher.
希望有帮助,弗兰克
这篇关于Objective-C:如何防止抽象泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!