1 | Accustoming Yourself to Objective-C | 熟悉Objective-C |
1.1 | Familiarize Yourself with Objective-C’s Roots | 了解Objective-C语言的起源 |
1.2 | Minimize Importing Headers in Headers | 在类的头文件中尽量少引入其他头文件 |
1.3 | Prefer Literal Syntax over the Equivalent Methods | 多用字面量语法,少用与之等价的方法 |
1.4 | Prefer Typed Constants to Preprocessor #define | 多用类型常量,少用#define预处理指令 |
1.5 | Use Enumerations for States, Options, and Status Codes | 用枚举表示状态、选项、状态码 |
2 | Objects, Messaging, and the Runtime | 对象、消息、运行期 |
2.1 | Understand Properties | 理解"属性"这一概念 |
2.2 | Access Instance Variables Primarily Directly When Accessing Them Internally | 在对象内部尽量直接访问实例变量 |
2.3 | Understand Object Equality | 理解"对象等同性"这一概念 |
2.4 | Use the Class Cluster Pattern to Hide Implementation Detail | 以"类族模式"隐藏实现细节 |
2.5 | Use Associated Objects to Attach Custom Data to Existing Classes | 在既有类中使用关联对象存放自定义数据 |
2.6 | Understand the Role of objc_msgSend | 理解objc_msgSend的作用 |
2.7 | Understand Message Forwarding | 理解消息转发机制 |
2.8 | Consider Method Swizzling to Debug Opaque Methods | 用"方法调配技术"调试"黑盒方法" |
2.9 | Understand What a Class Object Is | 理解"类对象"的用意 |
3 | Interface and API Design | 接口与API设计 |
3.1 | Use Prefix Names to Avoid Namespace Clashes | 用前缀避免命名空间冲突 |
3.2 | Have a Designated Initializer | 提供"全能初始化方法" |
3.3 | Implement the description Method | 实现description方法 |
3.4 | Prefer Immutable Objects | 尽量使用不可变对象 |
3.5 | Use Clear and Consistent Naming | 使用清晰而协调的命名方式 |
3.6 | Prefix Private Method Names | 为私有方法名加前缀 |
3.7 | Understand the Objective-C Error Model | 理解Objective-C错误模型 |
3.8 | Understand the NSCopying Protocol | 理解NSCopying协议 |
4 | Protocols and Categories | 协议与分类 |
4.1 | Use Delegate and Data Source Protocols for Interobject Communication | 通过委托与数据源协议进行对象间通信 |
4.2 | Use Categories to Break Class Implementations into Manageable Segments | 将类的实现代码分散到便于管理的数个分类之中 |
4.3 | Always Prefix Category Names on Third-Party Classes | 总是为第三方类的分类名称加前缀 |
4.4 | Avoid Properties in Categories | 勿在分类中声明属性 |
4.5 | Use the Class-Continuation Category to Hide Implementation Detail | 使用"class-continuation分类"隐藏实现细节" |
4.6 | Use a Protocol to Provide Anonymous Objects | 通过协议提供匿名对象 |
5 | Memory Management | 内存管理 |
5.1 | Understand Reference Counting | 理解引用计数 |
5.2 | Use ARC to Make Reference Counting Easier | 以ARC简化引用计数 |
5.3 | Release References and Clean Up Observation State Only in dealloc | 在dealloc方法中只释放引用并解除监听 |
5.4 | Beware of Memory Management with Exception-Safe Code | 编写"异常安全代码"时留意内存管理问题 |
5.5 | Use Weak References to Avoid Retain Cycles | 以弱引用避免保留环 |
5.6 | Use Autorelease Pool Blocks to Reduce High-Memory Waterline | 以"自动释放池块"降低内存峰值 |
5.7 | Use Zombies to Help Debug Memory-Management Problems | 用"僵尸对象"调试内存管理问题 |
5.8 | Avoid Using retainCount | 不要使用retainCount |
6 | Blocks and Grand Central Dispatch | 块与大中枢派发 |
6.1 | Understand Blocks | 理解"块"这一概念 |
6.2 | Create typedefs for Common Block Types | 为常用的块类型创建typedef |
6.3 | Use Handler Blocks to Reduce Code Separation | 用handler块降低代码分散程度 |
6.4 | Avoid Retain Cycles Introduced by Blocks Referencing the Object Owning Them | 用块引用其所属对象时不要出现保留环 |
6.5 | Prefer Dispatch Queues to Locks for Synchronization | 多用派发队列,少用同步锁 |
6.6 | Prefer GCD to performSelector and Friends | 多用GCD,少用performSelector系列方法 |
6.7 | Know When to Use GCD and When to Use Operation Queues | 掌握GCD及操作队列的使用时机 |
6.8 | Use Dispatch Groups to Take Advantage of Platform Scaling | 通过Dispatch Group机制,根据系统资源状况来执行任务 |
6.9 | Use dispatch_once for Thread-Safe Single-Time Code Execution | 使用dispatch_once来执行只需运行一次的线程安全代码 |
6.10 | Avoid dispatch_get_current_queue | 不要使用dispatch_get_current_queue |
7 | The System Frameworks | 系统框架 |
7.1 | Familiarize Yourself with the System Frameworks | 熟悉系统框架 |
7.2 | Prefer Block Enumeration to for Loops | 多用块枚举,少用for循环 |
7.3 | Use Toll-Free Bridging for Collections with Custom Memory-Management Semantics | 对自定义其内存管理语义的collection使用无缝桥接 |
7.4 | Use NSCache Instead of NSDictionary for Caches | 构建缓存时选用NSCache而非NSDictionary |
7.5 | Keep initialize and load Implementations Lean | 精简initialize与load的实现代码 |
7.6 | Remember that NSTimer Retains Its Target | 别忘了NSTimer会保留其目标对象 |