iPhone SDK @package vs. @private vs. @public 和 struct
嘿,我有一个非常简单的问题,需要更多的解释而不是调试,但我在许多类对象的接口定义中看到了关键字“@package”、“@private”、“@public”,甚至更奇怪的“struct {...}”。我已经能够在不使用上述任何内容的情况下制作完整的程序,所以我希望有人可以向我解释这些关键字的重要性。
谢谢
编辑:
等等,我现在明白了每个声明的限制,但是为什么你需要使用它们呢?您能澄清一下“struct {...}”的含义以及我如何使用它吗?再次感谢:D
Hey I have a really simple question that needs more of just an explanation than a debug, but I have seen in the interface definitions for many class objects the keywords "@package", "@private", "@public", and then even weirder "struct {...}". I have been able to make complete programs without using any of the aforementioned, so I was hoping someone could explain to me the significance of those keywords.
Thanks
EDIT:
Wait, I understand now that the restictions of each declaration but why would you ever need to use them? And can you clarify what "struct {...}" means and how I use it? Thanks again :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于软件包,您的问题在这里详细回答:什么是@package 指令在 Objective-C 中做什么?
struct 是一种 C 结构,可让您以单个名称访问多种数据类型。
@private 限制对变量的访问仅限于此类使用
@protected 限制对变量的访问仅限于此类和继承类(Obj-C 类中的默认值)
@package 限制对变量的访问仅限于框架使用
@ public 让每个人都可以访问此变量
编辑:
关于限制,限制对变量的访问是良好的 OO 实践,称为封装 http://en.wikipedia.org/wiki/Encapsulation_%28object-oriented_programming%29
Concerning Package, your Question is answered here in detail: What does the @package directive do in Objective-C?
struct is a C construct that lets you access multiple data types under a single name.
@private restricts access to variables to the use by just this class
@protected restricts access to variables to the use by just this class and inheriting classes ( default in Obj-C classes)
@package restricts access to variables to the use by the framework
@public lets everyone acces this variable
Edit:
Concerning the restriction, its good OO Practice to restrict access to variables, known as encapsulation http://en.wikipedia.org/wiki/Encapsulation_%28object-oriented_programming%29