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 like NSString.

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 as readwrite 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的更多相关文章

  1. Programming In Scala笔记-第十五章、Case Classes和模式匹配

    本章主要分析case classes和模式匹配(pattern matching). 一.简单例子 接下来首先以一个包含case classes和模式匹配的例子来展开本章内容. 下面的例子中将模拟实现 ...

  2. Programming In Scala笔记-第五章、Scala中的变量类型和操作

    这一章的一些基础性的东西,主要包括Scala中的基本变量类型,以及相关的一些操作符. 一.简单类型 下表中列出Scala语言中的基本类型,以及其字节长度,其中Byte, Short, Int, Lon ...

  3. Programming Entity Framework-dbContext 学习笔记第五章

    ### Programming Entity Framework-dbContext 学习笔记 第五章 将图表添加到Context中的方式及容易出现的错误 方法 结果 警告 Add Root 图标中的 ...

  4. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十五章:第一人称摄像机和动态索引

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十五章:第一人称摄像机和动态索引 代码工程地址: https://g ...

  5. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第五章:渲染流水线

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第五章:渲染流水线 学习目标 了解几个用以表达真实场景的标志和2D图像 ...

  6. 《Programming WPF》翻译 第9章 4.模板

    原文:<Programming WPF>翻译 第9章 4.模板 对一个自定义元素最后的设计考虑是,它是如何连接其可视化的.如果一个元素直接从FrameworkElement中派生,这将会适 ...

  7. 《Programming WPF》翻译 第8章 3.Storyboard

    原文:<Programming WPF>翻译 第8章 3.Storyboard Storyboard是动画的集合.如果你使用了标记,所有的动画必须要被定义在一个Storyboard中.(在 ...

  8. 《Programming WPF》翻译 第8章 2.Timeline

    原文:<Programming WPF>翻译 第8章 2.Timeline Timeline代表了时间的延伸.它通常还描述了一个或多个在这段时间所发生的事情.例如,在前面章节描述的动画类型 ...

  9. 《Programming WPF》翻译 第7章 1.图形基础

    原文:<Programming WPF>翻译 第7章 1.图形基础 WPF使得在你的应用程序中使用图形很容易,以及更容易开发你的显卡的能力.这有很多图形构架的方面来达到这个目标.其中最重要 ...

随机推荐

  1. jQuery特性

      CreateTime--2017年7月17日11:45:27Author:Marydon jQuery特性 1.jQuery取值 使用jQuery进行页面取值时,获取到的值的类型有两种:strin ...

  2. 常用Jar包下载

    Jackson包下载 :https://yunpan.cn/cBdPGeIESZ4jE  访问密码 36f7

  3. 【LeetCode】106. Construct Binary Tree from Inorder and Postorder Traversal

    Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder traversal of ...

  4. Linux命令-文件处理命令:cat

    cat /etc/issue 查看etc目录下面的issue文件内容(issue是linxu系统的欢迎文件) cat -n /etc/issue 查看文件内容的时候显示行号 tac /etc/issu ...

  5. bcdedit

    我的电脑装了双系统:Win2003 SP2(C盘)和Win2008 SP2(D盘),最近2003一启动就蓝屏unknown hard error,安全模式也进不去,恢复注册表等方法试过也不行,但200 ...

  6. AppCompat v23.2  -- Vectors的时代

    表示速度真快啊,刚公布的23.2,就有人写blog了 原文:https://medium.com/@chrisbanes/appcompat-v23-2-age-of-the-vectors-91cb ...

  7. IntelliJ IDEA 学习(三):IntelliJ IDEA 快捷键、配置优化

    一.两种方式可以设置快捷键: 1)setting -> keymap 想找到有关Idea工具的菜单或其他功能的话,可以再这里找到对应的快捷键   2)setting -> Editor - ...

  8. cocos2dx, 重新initWithSpriteFrameName与重新setTexture()+setTextureRect()区别

    比如我们有一个sprite是通过createWithSpriteFrameName创建的,现在我们需要为其更换贴图,有两种方法: 一种方法是再次调用createWithSpriteFrameName, ...

  9. HttpOperater

    using System; using System.IO; using System.Linq; using System.Net; using System.Text; using System. ...

  10. RPC服务框架dubbo(三):Dubbo支持的协议

    1.Dubbo 1.1 Dubbo官方推荐的协议. 1.2 本质:使用NIO和线程池进行处理. 1.3 缺点:大文件传输时可能出现文件传输失败问题. 2.RMI 2.1 JDK提供的协议,远程方法调用 ...