Objective-C:如何防止抽象泄漏 [英] Objective-C: how to prevent abstraction leaks

查看:100
本文介绍了Objective-C:如何防止抽象泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为在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。

推荐答案

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.

希望有帮助,
弗兰克

Hope it helps, Frank

这篇关于Objective-C:如何防止抽象泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆