iPhone SDK @package vs. @private vs. @public 和 struct

发布于 2024-09-15 18:31:56 字数 272 浏览 10 评论 0原文

嘿,我有一个非常简单的问题,需要更多的解释而不是调试,但我在许多类对象的接口定义中看到了关键字“@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林散布 2024-09-22 18:31:56

关于软件包,您的问题在这里详细回答:什么是@package 指令在 Objective-C 中做什么?

struct 是一种 C 结构,可让您以单个名称访问多种数据类型。

@private 限制对变量的访问仅限于此类使用

@protected 限制对变量的访问仅限于此类和继承类(Obj-C 类中的默认值)

@package 限制对变量的访问仅限于框架使用

@ public 让每个人都可以访问此变量

编辑:

struct person {         /* declares struct person */
int   age;
float weight;
char  name[25];
  } adam;

struct person joe;
joe.age = 23;        /* add values */
joe.weight = 147.8;    

关于限制,限制对变量的访问是良好的 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:

struct person {         /* declares struct person */
int   age;
float weight;
char  name[25];
  } adam;

struct person joe;
joe.age = 23;        /* add values */
joe.weight = 147.8;    

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文