《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
@implementationblock 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
readonlyin the interface, but asreadwritein 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使得在你的应用程序中使用图形很容易,以及更容易开发你的显卡的能力.这有很多图形构架的方面来达到这个目标.其中最重要 ...
随机推荐
- 〖Linux〗不知谁写的,很实用的Linux命令
第一部分 . sudo 运行上一条命令 sudo !! . HTTP方式共享当前目录 python -m SimpleHTTPServer . vim保存一个root用户文件 :w !sudo tee ...
- HDU 5389 Zero Escape(dp啊 多校)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5389 Problem Description Zero Escape, is a visual no ...
- 变动性算法源代码分析与使用示例(copy_backward、 transform、 replace_copy_if 等)
首先回顾前面的文章,我们把for_each 归类为非变动性算法,实际上它也可以算是变动性算法,取决于传入的第三个参数,即函数 指针.如果在函数内对容器元素做了修改,那么就属于变动性算法. 变动性算法源 ...
- 我的Android进阶之旅------>Android系统设置默认来电铃声、闹钟铃声、通知铃声
首先了解Android系统本身提供的默认铃声文件,这些文件都放在 /system/media/audio 文件夹下. /system/media/audio/ringtones 系统来电铃声 ...
- AutoFac文档8(转载)
目录 开始 Registering components 控制范围和生命周期 用模块结构化Autofac xml配置 与.net集成 深入理解Autofac 指导 关于 词汇表 泛型 给定一个开放的泛 ...
- C++ 基类指针和子类指针相互赋值
首先,给出基类animal和子类fish [cpp] view plaincopy //======================================================== ...
- ubuntu16.04字体设置
我在ubuntu下主要有2个应用,一个是终端,一个是firefox浏览器 1.在终端下,我喜欢“Courier 10 pitch regular”,字号是14.Courier是一种专门为程序员设计的字 ...
- Python在ubuntu下常用开发包名称
build-essential python3-setuptools python-setuptools-doc python3-all-dev python3-wheelwheel时pip支持的一种 ...
- vim资源帖
vimscript教程 http://learnvimscriptthehardway.stevelosh.com/ 阿信的vimscript http://www.axiaoxin.com/arti ...
- AESDK报错AEGP Magic Error的解决
原因是要先释放了流,再释放流的值,顺序问题导致报错. 解决方法是先释放流的值,再释放流 mSuites->StreamSuite2()->AEGP_DisposeStreamValue(v ...