class extension、class category、class-continuation category
2024-08-23 23:36:57
class extension
- Objective-C 2.0增加了class extensions用于解决两个问题:
- 允许一个对象可以拥有一个私有的interface,且可由编译器验证。
- 支持一个公有只读,私有可写的属性。
- extension更像是匿名的category
class category
- category更倾向于写在独立的文件中,之后这样命名“NSView+CustomAdditions.h”,在对应的.m文件中的block块中实现。所以,cagegory更倾向于用于对class进行功能的分离,用于组织类的功能模块。
- extension更倾向于在同一个类的.m文件的最上方写,而其实现则放在该类的implementation block中。
- 如少鸿上次提供的 UIImage+Display.h ,就是对系统的UIImage类的补充
Difference between Category and Class Extension?
- A category is a way to add methods to existing classes. They usually reside in files called "Class+CategoryName.h", like "NSView+CustomAdditions.h" (and .m, of course).
- A class extension is a category, except for 2 main differences:
- The category has no name. It is declared like this:
@interface SomeClass ()
- (void) anAdditionalMethod;
@end
- The implementation of the extension must be in the main @implementation block of the file.
- It's quite common to see a class extension at the top of a .m file declaring more methods on the class, that are then implemented below in the main @implementation section of the class. This is a way to declare "pseudo-private" methods (pseudo-private in that they're not really private, just not externally exposed).
class-continuation category
class-continuation 分类 见《Effective Objective-C 2.0》第27条
What is an Objective-C “class continuation”?
其实 class-continuation 就是 class extensions,叫法不一样而已
最新文章
- LINQ to SQL语句(12)之Delete和使用Attach
- CodeFirst进行数据迁移之添加字段
- HDU 1829 分组并查集
- HttpServletResponse
- redis哨兵配置主从
- jQuery easyui datagrid数据绑定
- linux-阿里云ECS部署PPTP(centos)
- xml学习总结(三)
- PHP发送微信模版消息
- 【JS】Intermediate8:jQuery:AJAX
- VS2013下的Nmake编译链接成win XP的可执行程序
- 关于mysql的安装
- JS一些小算术、1加到50、乘法口诀表、买鸡等
- JAVA泛型之<;? extends T>;:(通配符上限)和<;? super T>;(通配符下限)
- 复制vmware中的centos后无法上网问题
- mysql语法、特殊符号及正则表达式的使用
- hdu 3480 Division(四边形不等式优化)
- python logging 日志轮转文件不删除问题的解决方法
- react-native-pushy 热更新
- CSS — 贝塞尔曲线(cubic-bezier)
热门文章
- 我叫mt3.2更新公告
- PV(Pageviews)、访问(Visits)和访问者(Visitors)的区别
- [Xcode 实际操作]八、网络与多线程-(14)使用网址会话对象URLSession将地理坐标转换为地名
- Aandroid 解决apk打包过程中出现的“Certificate for <;jcenter.bintray.com>; doesn&#39;t match any of the subject alternative names: [*.aktana.com, aktana.com]”的问题
- suse 11入门学习
- HTTP1.1规范下载 6个文档组成
- gns3 拖出设备显示一个红色的s,无法启动虚拟设备
- 页面嵌套时js失效解决方法
- NFX UNISTACK 介绍
- python语法: