《Programming with Objective-C》第五章 Customizing Existing Classes
1.分类里面只新增函数,不要新增变量;虽然新增是语法合法的,但是编译器并不会为你的property合成相应的成员变量、setter和getter
Categories can be used to declare either instance methods or class methods but are not usually suitable for declaring additional properties. It’s valid syntax to include a property declaration in a category interface, but it’s not possible to declare an additional instance variable in a category. This means the compiler won’t synthesize any instance variable, nor will it synthesize any property accessor methods. You can write your own accessor methods in the category implementation, but you won’t be able to keep track of a value for that property unless it’s already stored by the original class.
2.扩展的方法在.m文件中的@implementation中实现
The methods declared by a class extension are implemented in the
@implementation
block for the original class so you can’t, for example, declare a class extension on a framework class, such as a Cocoa or Cocoa Touch class likeNSString
.
3.扩展可以看做是匿名的分类,但是扩展中可以新增变量
class extensions are often referred to as anonymous categories.
Unlike regular categories, a class extension can add its own properties and instance variables to a class.
4.在.h中将属性声明为readonly,但是在.m中的扩展中声明为readwrite,这样内部可读写,外部只能读
It’s common, for example, to define a property as
readonly
in the interface, but asreadwrite
in a class extension declared above the implementation, in order that the internal methods of the class can change the property value directly.
5.Objective-C并不像C++那样,一编译一链接就变成机器码,它执行的时候还需要一个Runtime系统来支持
Objective-C is more than just a language that is compiled down to machine code. Instead, it requires a runtime system in place to execute that code.
《Programming with Objective-C》第五章 Customizing Existing Classes的更多相关文章
- Programming In Scala笔记-第十五章、Case Classes和模式匹配
本章主要分析case classes和模式匹配(pattern matching). 一.简单例子 接下来首先以一个包含case classes和模式匹配的例子来展开本章内容. 下面的例子中将模拟实现 ...
- Programming In Scala笔记-第五章、Scala中的变量类型和操作
这一章的一些基础性的东西,主要包括Scala中的基本变量类型,以及相关的一些操作符. 一.简单类型 下表中列出Scala语言中的基本类型,以及其字节长度,其中Byte, Short, Int, Lon ...
- Programming Entity Framework-dbContext 学习笔记第五章
### Programming Entity Framework-dbContext 学习笔记 第五章 将图表添加到Context中的方式及容易出现的错误 方法 结果 警告 Add Root 图标中的 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十五章:第一人称摄像机和动态索引
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十五章:第一人称摄像机和动态索引 代码工程地址: https://g ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第五章:渲染流水线
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第五章:渲染流水线 学习目标 了解几个用以表达真实场景的标志和2D图像 ...
- 《Programming WPF》翻译 第9章 4.模板
原文:<Programming WPF>翻译 第9章 4.模板 对一个自定义元素最后的设计考虑是,它是如何连接其可视化的.如果一个元素直接从FrameworkElement中派生,这将会适 ...
- 《Programming WPF》翻译 第8章 3.Storyboard
原文:<Programming WPF>翻译 第8章 3.Storyboard Storyboard是动画的集合.如果你使用了标记,所有的动画必须要被定义在一个Storyboard中.(在 ...
- 《Programming WPF》翻译 第8章 2.Timeline
原文:<Programming WPF>翻译 第8章 2.Timeline Timeline代表了时间的延伸.它通常还描述了一个或多个在这段时间所发生的事情.例如,在前面章节描述的动画类型 ...
- 《Programming WPF》翻译 第7章 1.图形基础
原文:<Programming WPF>翻译 第7章 1.图形基础 WPF使得在你的应用程序中使用图形很容易,以及更容易开发你的显卡的能力.这有很多图形构架的方面来达到这个目标.其中最重要 ...
随机推荐
- chrome 禁止自动更新
禁止chrome自动更新 CreateTime--2017年7月4日09:07:01Author:Marydon 版本号:59.0.3071.115 x64 第一步:禁止Google更新服务 参考 ...
- eclipse maven Cannot change version of project facet Dynamic web module to 3.0
eclipse maven Cannot change version of project facet Dynamic web module to 3.0 (eclipse 修改maven项目的 ...
- Linux命令格式
- 摘:"error LNK2019: 无法解析的外部符号 该符号在函数 中被引用" 错误原因
例如“error LNK2019: 无法解析的外部符号error LNK2001: 无法解析的外部符号“private: static struct _OVERLAPPED CUsbCom::g_Wr ...
- spring in action小结3 运行时值注入
讨论依赖注入的时候,通常讨论的是一个bean引用注入到另一个bean的属性或者构造器参数中.bean装配的另一个方面是将值注入到bean的属性或者构造器参数中.避免硬编码的方式就是运行时确定值. sp ...
- linux下重新定位SVN URL方法
linux下重新定位SVN URL方法: 如果更换了SVN服务器,就需要重新定位,指向新的SVN URL. 重新定位命令:svn switch --relocate 原svn地址 新svn地址 ...
- Docker 监控的一点想法
目前项目内部署了docker,于是涉及到关于监控的事情,参考一些经典实例以及一些自己的想法,总结一下思路. 1.关于监控的内容 监控宿主机本身 监控宿主机本身还是比较简单的,同其他服务器监控类似,对c ...
- web.py+fastcgi+nginx 502错误解决
用web.py照着官网在服务器上搭好了后台.这次很奇怪地出现了一个Nginx 502 Bad Gateway的错误. 执行上面的kill `pgrep -f "python /path/to ...
- std::string与output-operator"<<"的兼容问题
经查阅资料得知,“在某些编译器下std::string,需要使用c_str()才能作为output-operator "<<" 的参数” std::string tit ...
- 使用python对mysql主从进行监控,并调用钉钉发送报警信息
1.编写python的监控脚本 A.通过获取mysql库中的状态值来判断这个mysql主从状态是否正常 B.进行两个状态值的判断 C.进行调取钉钉机器人,发送消息 2.设置定时任务进行脚本运行 cro ...