前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【iOS】The differences between Class Extension and Header File 类扩展与头文件的区别

【iOS】The differences between Class Extension and Header File 类扩展与头文件的区别

作者头像
zhaokang555
发布2023-10-17 09:10:56
1050
发布2023-10-17 09:10:56
举报

.

As the name suggests, they extend the class. A class continuation is another name. The class extension is commonly used to declare private methods and properties. You want the class extension to be visible to the @implementation, and not in the header file.

Types and methods in the header file are generally intended to be public -- available to any client.

Example: The property declared in the class extension will not be visible/accessible to clients who #import the header, but it will be usable by the @implementationbecause the @implementation can see the declarations of the class extension.

So this can be used to emulate restricted access for your ivars and methods. This is useful because ObjC methods and properties cannot be specified as private/protected/public (e.g. using @public).

Class extensions differ from categories primarily because extensions may declare storage (e.g. properties which will produce backing ivars).

.

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2015-08-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档