├── AI.md ├── APM.md ├── Algorithm └── BinaryTree.md ├── AutoLayout.md ├── Blockchain.md ├── Books ├── TCPL-5-1.png └── The_C_Programming_Language.md ├── C++.md ├── C.md ├── Cache.md ├── Compression.md ├── DNS.md ├── DesignPattern.md ├── ES6.md ├── GCD.md ├── HTTP.md ├── IM.md ├── Image.md ├── Interview.md ├── KVC&KVO.md ├── OC_Block.md ├── OC_Category.md ├── OC_Class_Object.md ├── OC_Property.md ├── OC_Runtime.md ├── OpenPlatform.md ├── OpenSource.md ├── README.md ├── README[DEPRECATED].md ├── React.md ├── ResponderChain.md ├── Reverse.md ├── Runloop.md ├── Singleton.md ├── Swift.md ├── Time.md ├── TypeScript.md ├── WeChatTech.md ├── Weex.md ├── lldb.md ├── 编程语言 ├── Objective-C │ ├── Effective_Objective-C_2.0_读书笔记.md │ └── README.md └── README.md └── 网络 ├── HTTP ├── README.md └── URL_Session_Programming_Guide_zh.md ├── README.md ├── TCP └── README.md └── XMPP └── README.md /AI.md: -------------------------------------------------------------------------------- 1 | # 人工智能 2 | 3 | 大纲 4 | - 基础数学 5 | - 线性代数 6 | - 概率论 7 | - 数理统计 8 | - 最优化方法 9 | - 信息论 10 | - 形式逻辑 11 | - 机器学习 12 | 13 | ## 机器学习 14 | 15 | 什么是机器学习? 16 | > 从大量现象中提取反复出现的规律和模式。这一过程在人工智能中的实现就是机器学习。 -- 摘自 王天一 极客时间专栏 -------------------------------------------------------------------------------- /APM.md: -------------------------------------------------------------------------------- 1 | # APM 2 | 3 | ## 重要的技术指标 4 | - CPU 5 | - Memory 6 | - FPS 7 | - Network 8 | - Power 9 | 10 | ## SDK 11 | - [听云](http://www.tingyun.com) 12 | - [OneAPM](http://www.oneapm.com) 13 | - [Firebase](https://firebase.google.com) 14 | - [阿里百川](http://baichuan.taobao.com) 15 | 16 | ## Open Source 17 | - [GodEye](https://github.com/zixun/GodEye) (Swift) 18 | 19 | ## Ref 20 | - [iOS 性能监控 SDK —— Wedjat(华狄特)开发过程的调研和整理](https://github.com/aozhimin/iOS-Monitor-Platform) by aozhimin 21 | - [揭秘 APM iOS SDK 的核心技术](https://github.com/aozhimin/iOS-APM-Secrets) by aozhimin 22 | - [Benchmarking](http://nshipster.cn/benchmarking/) by Mattt Thompson, Croath Liu 译 2014 23 | - [移动端监控体系之技术原理剖析](http://www.jianshu.com/p/8123fc17fe0e) by Joy___ 2017 24 | - [NeteaseAPM iOS SDK 技术实现](https://neyoufan.github.io/2016/12/16/ios/NeteaseAPM%20iOS%20SDK技术实现/NeteaseAPM%20iOS%20SDK技术实现/) by 网易杭州前端技术部 · 朱志强 2016 25 | - [微信读书 iOS 质量保证及性能监控](http://wereadteam.github.io/2016/12/12/Monitor/) by 微信读书技术团队 · tower 2016 -------------------------------------------------------------------------------- /Algorithm/BinaryTree.md: -------------------------------------------------------------------------------- 1 | # Binary Tree 二叉树 2 | 3 | 4 | - [1. TreeNode](#1-treenode) 5 | - [2. Preorder Traversal 前序遍历](#2-preorder-traversal-前序遍历) 6 | - [3. Inorder Traversal 中序遍历](#3-inorder-traversal-中序遍历) 7 | - [4. Postorder Traversal 后序遍历](#4-postorder-traversal-后序遍历) 8 | - [5. Level Order Traversal 层次遍历](#5-level-order-traversal-层次遍历) 9 | - [6. MaxDepth 计算最大深度](#6-maxdepth-计算最大深度) 10 | - [7. MinDepth 计算最小深度](#7-mindepth-计算最小深度) 11 | - [8. Invert 翻转](#8-invert-翻转) 12 | - [9. IsSameTree 判等](#9-issametree-判等) 13 | - [10. IsSymmetric 判断是否对称](#10-issymmetric-判断是否对称) 14 | - [11. IsBalanced 判断是否平衡](#11-isbalanced-判断是否平衡) 15 | - [12. Binary Search Tree (BST) 二叉搜索树](#12-binary-search-tree-bst-二叉搜索树) 16 | - [12.1. IsValidBST](#121-isvalidbst) 17 | - [12.2. TrimBST](#122-trimbst) 18 | - [13. Depth-First-Search (DFS) 深度优先搜索算法](#13-depth-first-search-dfs-深度优先搜索算法) 19 | - [14. Breadth-First-Search (BFS) 广度优先搜索算法](#14-breadth-first-search-bfs-广度优先搜索算法) 20 | 21 | 22 | 23 | ## 1. TreeNode 24 | ``` C 25 | struct TreeNode { 26 | int val; 27 | struct TreeNode *left; 28 | struct TreeNode *right; 29 | }; 30 | ``` 31 | 32 | ## 2. Preorder Traversal 前序遍历 33 | 34 | ## 3. Inorder Traversal 中序遍历 35 | Ref: [94. Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/description/) 36 | ``` C 37 | /** 38 | * Definition for a binary tree node. 39 | * struct TreeNode { 40 | * int val; 41 | * struct TreeNode *left; 42 | * struct TreeNode *right; 43 | * }; 44 | */ 45 | /** 46 | * Return an array of size *returnSize. 47 | * Note: The returned array must be malloced, assume caller calls free(). 48 | */ 49 | int* inorderTraversal(struct TreeNode* root, int* returnSize) { 50 | 51 | } 52 | ``` 53 | 54 | ## 4. Postorder Traversal 后序遍历 55 | 56 | ## 5. Level Order Traversal 层次遍历 57 | ``` C 58 | int** levelOrder(struct TreeNode* root, int** columnSizes, int* returnSize) { 59 | 60 | } 61 | ``` 62 | 63 | ## 6. MaxDepth 计算最大深度 64 | Ref: [LeetCode 104. Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/description/) 65 | ``` C 66 | /** 67 | * Definition for a binary tree node. 68 | * struct TreeNode { 69 | * int val; 70 | * struct TreeNode *left; 71 | * struct TreeNode *right; 72 | * }; 73 | */ 74 | int maxDepth(struct TreeNode* root) { 75 | if (root) { 76 | int leftMaxDepth = maxDepth(root->left); 77 | int rightMaxDepth = maxDepth(root->right); 78 | if (leftMaxDepth >= rightMaxDepth) { 79 | return leftMaxDepth + 1; 80 | } else { 81 | return rightMaxDepth + 1; 82 | } 83 | } 84 | return 0; 85 | } 86 | ``` 87 | 88 | ## 7. MinDepth 计算最小深度 89 | 90 | ## 8. Invert 翻转 91 | Ref: [LeetCode 226. Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree/description/) 92 | ``` C 93 | /** 94 | * Definition for a binary tree node. 95 | * struct TreeNode { 96 | * int val; 97 | * struct TreeNode *left; 98 | * struct TreeNode *right; 99 | * }; 100 | */ 101 | struct TreeNode* invertTree(struct TreeNode* root) { 102 | if (root) { 103 | struct TreeNode *temp = root->left; 104 | root->left = invertTree(root->right); 105 | root->right = invertTree(temp); 106 | } 107 | return root; 108 | } 109 | ``` 110 | 111 | ## 9. IsSameTree 判等 112 | Ref: [LeetCode 100. Same Tree](https://leetcode.com/problems/same-tree/description/) 113 | ``` C 114 | /** 115 | * Definition for a binary tree node. 116 | * struct TreeNode { 117 | * int val; 118 | * struct TreeNode *left; 119 | * struct TreeNode *right; 120 | * }; 121 | */ 122 | bool isSameTree(struct TreeNode* p, struct TreeNode* q) { 123 | if (!p && q) return false; 124 | if (p && !q) return false; 125 | if (!p && !q) return true; 126 | 127 | if (p->val != q->val) return false; 128 | if (!isSameTree(p->left, q->left)) return false; 129 | if (!isSameTree(p->right, q->right)) return false; 130 | 131 | return true; 132 | } 133 | ``` 134 | 135 | ## 10. IsSymmetric 判断是否对称 136 | Ref: [LeetCode 101. Symmetric Tree](https://leetcode.com/problems/symmetric-tree/description/) 137 | ``` C 138 | /** 139 | * Definition for a binary tree node. 140 | * struct TreeNode { 141 | * int val; 142 | * struct TreeNode *left; 143 | * struct TreeNode *right; 144 | * }; 145 | */ 146 | bool isLeaf(struct TreeNode* node) { 147 | if (!node) return true; 148 | if (!node->left && !node->right) return true; 149 | return false; 150 | } 151 | 152 | bool isMirror(struct TreeNode* node1, struct TreeNode* node2) { 153 | if (node1 && !node2) return false; 154 | if (!node1 && node2) return false; 155 | if (!node1 && !node2) return true; 156 | if (node1->val != node2->val) return false; 157 | if (isLeaf(node1) && isLeaf(node2) && node1->val == node2->val) return true; 158 | 159 | return isMirror(node1->left, node2->right) && isMirror(node1->right, node2->left); 160 | } 161 | 162 | bool isSymmetric(struct TreeNode* root) { 163 | if (!root) return true; 164 | return isMirror(root->left, root->right); 165 | } 166 | ``` 167 | 168 | ## 11. IsBalanced 判断是否平衡 169 | 170 | > a height-balanced binary tree is defined as: a binary tree in which the depth of the two subtrees of every node never differ by more than 1. 171 | 172 | Ref: [LeetCode 110. Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/description/) 173 | ``` C 174 | /** 175 | * Definition for a binary tree node. 176 | * struct TreeNode { 177 | * int val; 178 | * struct TreeNode *left; 179 | * struct TreeNode *right; 180 | * }; 181 | */ 182 | bool isBalanced(struct TreeNode* root) { 183 | 184 | } 185 | ``` 186 | 187 | ## 12. Binary Search Tree (BST) 二叉搜索树 188 | 189 | ### 12.1. IsValidBST 190 | Ref: [LeetCode 98. Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/description/) 191 | ``` C 192 | /** 193 | * Definition for a binary tree node. 194 | * struct TreeNode { 195 | * int val; 196 | * struct TreeNode *left; 197 | * struct TreeNode *right; 198 | * }; 199 | */ 200 | bool isValidBST(struct TreeNode* root) { 201 | 202 | } 203 | ``` 204 | 205 | ### 12.2. TrimBST 206 | Ref: [LeetCode 669. Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree/description/) 207 | ``` C 208 | ``` 209 | 210 | ## 13. Depth-First-Search (DFS) 深度优先搜索算法 211 | ... 212 | 213 | ## 14. Breadth-First-Search (BFS) 广度优先搜索算法 214 | ... -------------------------------------------------------------------------------- /AutoLayout.md: -------------------------------------------------------------------------------- 1 | # Auto Layout 2 | 3 | ## 1. Cassowary 算法 4 | 5 | ## 2. NSLayoutConstraint 6 | 7 | ## 3. Masonry 到底做了什么? 8 | 9 | ## 4. References 10 | - [深入剖析 Auto Layout,分析 iOS 各版本新增特性](https://github.com/ming1016/study/wiki/深入剖析Auto-Layout,分析iOS各版本新增特性) by 戴铭 11 | - [孕孕的三个问题之——为什么使用 Auto Layout 之后手动修改 frame 无效](https://lvwenhan.com/autolayout-club/472.html) by by JohnLui 2015 12 | - [孕孕的三个问题之——使用 Auto Layout 之后什么时候才能获得正确的 frame?](https://lvwenhan.com/autolayout-club/473.html) by JohnLui 2015 -------------------------------------------------------------------------------- /Blockchain.md: -------------------------------------------------------------------------------- 1 | # 区块链 Blockchain 2 | 3 | ## Ref 4 | - [区块链理论学习入门指南](https://daimajia.com/2017/08/24/how-to-start-blockchain-learning) by 代码家 2017.08 5 | - [从投资角度看待区块链](https://daimajia.com/2017/09/01/invest-blockchain) by 代码家 2017.09 6 | - [PoW,PoS,DPoS 综述](https://daimajia.com/2017/09/14/pow-and-pos) by 代码家 2017.09 7 | - [区块链世界来龙去脉,峰瑞资本内部分享](https://daimajia.com/2018/02/10/blockchain-share-in-freesfund) by 代码家 2018.02 8 | - [区块链入门教程](http://www.ruanyifeng.com/blog/2017/12/blockchain-tutorial.html) by 阮一峰 2017.12 9 | - [比特币入门教程](http://www.ruanyifeng.com/blog/2018/01/bitcoin-tutorial.html) by 阮一峰 2018.01 10 | - [加密货币的本质](http://www.ruanyifeng.com/blog/2018/01/cryptocurrency-tutorial.html) by 阮一峰 2018.01 11 | - [分布式一致性与共识算法](https://draveness.me/consensus) by draveness 2017.12 -------------------------------------------------------------------------------- /Books/TCPL-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamjiyixuan/iOS-dev-skill-map/3443673805be5696aa95588e9bb90be586101109/Books/TCPL-5-1.png -------------------------------------------------------------------------------- /Books/The_C_Programming_Language.md: -------------------------------------------------------------------------------- 1 | # The C Programming Language (Second Edition) 2 | 3 | > Brian W. Kernighan, Dennis M. Ritchie 4 | 5 | 6 | 7 | - [Preface 序](#preface-序) 8 | - [Preface to the First Edition](#preface-to-the-first-edition) 9 | - [Introduction 引言](#introduction-引言) 10 | - [Chapter 1. A Tutorial Introduction](#chapter-1-a-tutorial-introduction) 11 | - [Chapter 2. Types, Operators, and Expressions](#chapter-2-types-operators-and-expressions) 12 | - [Chapter 3. Control Flow](#chapter-3-control-flow) 13 | - [Chapter 4. Functions and Program Structure](#chapter-4-functions-and-program-structure) 14 | - [Chapter 5. Pointers and Array 指针与数组](#chapter-5-pointers-and-array-指针与数组) 15 | - [5.1 Pointers and Addresses 指针与地址](#51-pointers-and-addresses-指针与地址) 16 | - [5.2 Pointers and Function Arguments 指针与函数参数](#52-pointers-and-function-arguments-指针与函数参数) 17 | - [Chapter 6. Structures](#chapter-6-structures) 18 | - [Chapter 7. Input and Output](#chapter-7-input-and-output) 19 | - [Chapter 8. The UNIX System Interface](#chapter-8-the-unix-system-interface) 20 | - [Appendix A. Reference Manual](#appendix-a-reference-manual) 21 | - [Appendix B. Standard Library](#appendix-b-standard-library) 22 | - [Appendix C. Summary of Changes](#appendix-c-summary-of-changes) 23 | 24 | 25 | 26 | ## Preface 序 27 | 28 | The computing world has undergone a revolution since the publication of The C Programming Language in 1978. Big computers are much bigger, and personal computers have capabilities that rival the mainframes of a decade ago. During this time, C has changed too, although only modestly, and it has spread 29 | far beyond its origins as the language of the UNIX operating system. 30 | 31 | 自从 1978 年《The C Programming Language》一书出版以来,计算机领域经历了一场革命。大型计算机的功能越来越强大,而个人计算机的性能也可以与十多年前的大型机相媲美。在此期间,C 语言也在悄悄地演进,其发展早己超出了它仅仅作为 UNIX 操作系统的编程语言的研衷。 32 | 33 | The growing popularity of C, the changes in the language over the years, and the creation of compilers by groups not involved in its design, combined to 34 | demonstrate a need for a more precise and more contemporary definition of the language than the first edition of this book provided. In 1983, the American National Standards Institute (ANSI) established a committee whose goal was to produce "an unambiguous and machine-independent definition of the language C," while still retaining its spirit. The result is the ANSI standard for C. 35 | 36 | C 语言普及程度的逐渐增加以及该语言本身的发展,加之很多组织开发出了与其设计有所不同的编译器,所有这一切都要求对 C 语言有一个比本书第 1 版更精确、更适应其发展的定义。1983 年,美国国家标准协会(ANSI)成立了一个委员会,其目标是制定**一个无歧义性的且与具体机器无关的 C 语言定义**,而同时又要保持 C 语言原有的**精神**。结果产生了 C 语言的 ANSI 标准。 37 | 38 | The standard formalizes constructions that were hinted at but not described in the first edition, particularly structure assignment and enumerations. It provides a new form of function declaration that permits cross-checking of definition with use. It specifiesa standard library, with an extensive set of functions for performing input and output, memory management, string manipulation, and similar tasks. It makes precise the behavior of features that were not spelled out in the original definition, and at the same time states explicitly which aspects of the language remain machine-dependent. 39 | 40 | ANSI 标准规范了一些在本书第 1 版中提及但没有具体描述的结构,特别是结构赋值和枚举。该标准还提供了一种新的函数声明形式,允许在使用过程中对函数的定义进行交叉检查。标准中还详细说明了一个具有标准输入/输出、内存管理和字符串操作等扩展函数集的标准库。它精确地说明了在 C 语言原始定义中并不明晰的某些特性的行为,同时还明确了 C 语言中与具体机器相关的一些特性。 41 | 42 | This second edition of The C Programming Language describes C as defined by the ANSI standard. Although we have noted the places where the language has evolved, we have chosen to write exclusively in the new form. For the most part, this makes no significant difference; the most visible change is the new form of function declaration and definition. Modern compilers already support most features of the standard. 43 | 44 | 本书第 2 版介绍的是 ANSI 标准定义的 C 语言。尽管我们已经注意到了该语言中已经变化了的地方,但我们还是决定在这里只列出它们的新形式。最重要的原因是,新旧形式之间并没有太大的差别;最明显的变化是函数的声明和定义。目前的编译器已经能够支持该标准的大部分特性。 45 | 46 | We have tried to retain the brevity of the first edition. C is not a big language, and it is not well served by a big book. We have improved the exposition of critical features, such as pointers, that are central to C programming. We have refined the original examples, and have added new examples in several chapters. For instance, the treatment of complicated declarations is augmented by programs that convert declarations into words and vice versa. As before, all examples have been tested directly from the text, which is in machine-readable form. 47 | 48 | 我们将尽力保持本书第 1 版的简洁性。C 语言并不是一种大型语言,也不需要用一本很厚的书来描述。我们在讲解一些关键特性(比如指针)时做了改进,它是 C 语言程序设计的核心。我们重新对以前的例子进行了精炼,并在某些章节中增加了一些新例子。例如,我们通过实例程序时复杂的声明进行处理,以将复杂的声明转换为描述性的说明或反之。像前一版中的例子一样,本版中所有例子都以可被机器读取的文本形式直接通过了测试。 49 | 50 | Appendix A, the reference manual, is not the standard, but our attempt to convey the essentials of the standard in a smaller space. It is meant for easy comprehension by programmers, but not as a definition for compiler writersthat role properly belongs to the standard itself. Appendix B is a summary of the facilities of the standard library. It too is meant for reference by programmers, not implementers. Appendix C is a concise summary of the changes from the original version. 51 | 52 | 附录 A 只是一个参考手册,而非标准,我们希望通过较少的篇幅概述标准中的要点。该附录的目的是帮助程序员更好地理解语言本身,而不是为编译器的实现者提供一个精确的定义——这正是语言标准所应当扮演的角色。附录 B 对标准库提供的功能进行了总结,它同样是面向程序员而非编译器实现者的。附录 C 对 ANSI 标准相对于以前版本所做的变更进行了小结。 53 | 54 | As we said in the preface to the first edition, C "wears well as one's experience with it grows." With a decade more experience, we still feel that way. We hope that this book will help you to learn C and to use it well. 55 | 56 | 我们在第 1 版中曾说过:”随着使用经验的增加,使用者会越来越感到得心应手”。经过十几年的实践,我们仍然这么认为。我们希望这本书能够帮助读者学好并用好 C 语言。 57 | 58 | We are deeply indebted to friends who helped us to produce this second edition. Jon Bentley, Doug Gwyn, Doug Mcllroy, Peter Nelson, and Rob Pike gave us perceptive comments on almost every page of draft manuscripts. We are grateful for careful reading by Al Aho, Dennis Allison, Joe Campbell, G. R. Emlin, Karen Fortgang, Allen Holub, Andrew Hume, Dave Kristol, John Linderman, Dave Prosser, Gene Spafford, and Chris Van Wyk. We also received helpful suggestions from BHl Cheswick, Mark Kernighan, Andy Koenig, Robin Lake, Tom London, Jim Reeds, Clovis Tondo, and Peter Weinberger. Dave Prosser answered many detailed questions about the ANSI standard. We used Bjarne Stroustrup's C++ translator extensively for local testing of our programs, and Pave Kristol provided us with an ANSI C compiler for final testing, Rich Drechsler helped greatly with typesetting. 59 | 60 | Our sincere thanks to all. 61 | 62 | ## Preface to the First Edition 63 | ... 64 | 65 | ## Introduction 引言 66 | C is a general-purpose programming language. It has been closely associated with the UNIX system where it was developed, since both the system and most of the programs that run on it are written in C. The language, however, is not tied to anyone operating system or machine; and although it has been called a "system programming language" because it is useful for writing compilers and operating systems, it has been used equally well to write major programs in many different domains. 67 | 68 | C 语言是一种通用的程序设计语言。它同 UNIX 系统之间具有非常密切的联系,C 语言是在 UNIX 系统上开发的,并且,无论是 UNIX 系统本身还是其上运行的大部分程序,都是用 C 语言编写的。但是 C 语言并不受限于任何一种操作系统或机器。由于它很适合用来编写编译器和操作系统,因此被称为“系统编程语言”,但它同样适合于编写不同领城中的大多数程序。 69 | 70 | Many of the important ideas of C stem from the language BCPL, developed by Martin Richards. The influence of BCPL on C proceeded indirectly through the language B, which was written by Ken Thompson in 1970 for the first UNIX system on the DEC PDP-7. 71 | 72 | C 语言的很多重要概念来源于由 Martin Richards 开发的 BCPL 语言。BCPL 对 C 语言的影响间接地来自于 B 语言,它是 Ken Thompson 为第一个 UNIX 系统而于 1970 年在 DEC PDP-7 计算机上开发的。 73 | 74 | BCPL and Bare "typeless" languages. By contrast, C provides a variety of data types. The fundamental types are characters, and integers and floatingpoint numbers of several sizes. In addition, there is a hierarchy of derived data types created with pointers, arrays, structures, and unions. Expressions are formed from operators and operands; any expression, including an assignment or a function call, can be a statement. Pointers provide for machine-independent address arithmetic. 75 | 76 | BCPL 和 B 语言都是“无类型”的语言。相比较而言,C 语言提供了很多数据类型。其基本类型包括字符、具有多种长度的整型和浮点数等。另外,还有通过指针、数组、结构和联合派生的各种数据类型。表达式由运算符和操作数组成任何一个表达式,包括赋值表达式或函数调用表达式,都可以是一个语句。指针提供了与具体机器无关的地址算术运算。 77 | 78 | C provides the fundamental control-flow constructions required for well-structured programs: statement grouping, decision making (if-else), selecting one of a set of possible cases (switch), looping with the termination test at the top (while, for) or at the bottom (do), and early loop exit (break). 79 | 80 | C 语言为实现结构良好的程序提供了基本的控制流结构:语句组、条件判断(if-else)、多路选择(switch)、终止测试在顶部的循环(while、for)、终止测试在底部的循环(do)、提前跳出循环(break)等。 81 | 82 | Functions may return values of basic types, structures, unions, or pointers. Any function may be called recursively. Local variables are typically "automatic," or created anew with each invocation. Function definitions may not be nested but variables may be declared in a block-structured fashion. The functions of a C program may exist in separate source files that are compiled separately. Variables may be internal to a function, external but known only within a single source file, or visible to the entire program. 83 | 84 | 函数可以返回基本类型、结构、联合或指针类型的值。任何函数都可以递归调用。局部变量通常是“自动的”,即在每次函数调用时重新创建。函数定义可以不是嵌套的,但可以用块结构的方式声明变量。一个 C 语言程序的不同函数可以出现在多个单独编译的不同源文件中。变量可以只在函数内部有效,也可以在函数外部但仅在一个源文件中有效,还可以在整个程序中都有效。 85 | 86 | A preprocessing step performs macro substitution on program text, inclusion of other source files, and conditional compilation. 87 | 88 | 编译的预处理阶段将对程序文本进行宏替换、包含其它源文件以及进行条件编译。 89 | 90 | C is a relatively "low level" language. This characterization is not pejorative; it simply means that C deals with the same sort of objects that most computers do, namely characters, numbers, and addresses. These may be combined and moved about with the arithmetic and logical operators implemented by real machines. 91 | 92 | C 语言是一种相对“低级”的语言。这种说法并没有什么贬义,它仅仅意味着 C 语言可以处理大部分计算机能够处理的对象,比如字符、数字和地址。这些对象可以通过具体机器实现的算术运算符和逻辑运算符组合在一起并移动。 93 | 94 | C provides no operations to deal directly with composite objects such as character strings, sets, lists, or arrays. There are no operations that manipulate an entire array or string, although structures may be copied as a unit. The language does not define any storage allocation facility other than static definition and the stack discipline provided by the local variables of functions; there is no heap or garbage collection. Finally, C itself provides no input/output facilities; there are no READ or WRITE statements, and no built-in file access methods. All of these higher-level mechanisms must be provided by explicitlycalled functions. Most C implementations have included a reasonably standard collection of such functions. 95 | 96 | Similarly, C offers only straightforward, single-thread control flow: tests, loops, grouping, and subprograms, but not multiprogramming, parallel operations, synchronization, or coroutines. 97 | 98 | Although the absence of some of these features may seem like a grave deficiency ("You mean I have to call a function to compare two character strings?"), keeping the language down to modest size has real benefits. Since C is relatively small, it can be described in a small space, and learned quickly. A programmer can reasonably expect to know and understand and indeed regularly use the entire language. 99 | 100 | For many years, the definition of C was the reference manual in the first edition of The C Programming Language. In 1983, the American National Standards Institute (ANSI) established a committee to provide a modern, comprehensive definition of C. The resulting definition, the ANSI standard, or "ANSI C," was completed late in 1988. Most of the features of the standard are already supported by modern compilers. 101 | 102 | The standard is based on the original reference manual. The language is relatively little changed; one of the goals of the standard was to make sure that most existing programs would remain valid, or, failing that, that compilers could produce warnings of new behavior. 103 | 104 | For most programmers, the most important change is a new syntax for declaring and defining functions. A function declaration can now include a description of the arguments of the function; the definition syntax changes to match. This extra information makes it much easier for compilers to detect errors caused by mismatched arguments; in our experience, it is a very useful addition to the language. 105 | 106 | There are other small-scale language changes. Structure assignment and enumerations, which had been widely available, are now officially part of the language. Floating-point computations may now be done in single precision. The properties of arithmetic, especially for unsigned types, are clarified. The preprocessor is more elaborate. Most of these changes will have only minor effects on most programmers. 107 | 108 | A second significant contribution of the standard is the definition of a library 109 | to accompany C. It specifies functions for accessing the operating system (for instance, to read and write files), formatted input and output, memory allocation, string manipulation, and the like. A collection of standard headers provides uniform access to declarations of functions and data types. Programs that use this library to interact with a host system are assured of compatible behavior. Most of the library is closely modeled on the "standard 1/0 library" of the UNIX system. This library was described in the first edition, and has been widely used on other systems as well. Again, most programmers will not see much change. 110 | 111 | Because the data types and control structures provided by C are supported directly by most computers, the run-time library required to implement selfcontained programs is tiny. The standard library functions are only called explicitly, so they can be avoided if they are not needed. Most can be written in C, and except for the operating system details they conceal, are themselves portable. 112 | 113 | Although C matches the capabilities of many computers, it is independent of any particular machine architecture. With a little care' it is easy to write portable programs, that is, programs that can be run without change on a variety of hardware. The standard makes portability issues explicit, and prescribes a set of constants that characterize the machine on which the program is run. 114 | 115 | C is not a strongly-typed language, but as it has evolved, its type-checking has been strengthened. The original definition of C frowned on, but permitted, the interchange of pointers and integers; this has long since been eliminated, and the standard now requires the proper declarations and explicit conversionsthat had already been enforced by good compilers. The new function declarations are another step in this direction. Compilers will warn of most type errors, and there is no automatic conversion of incompatible data types. Nevertheless, C retains the basic philosophy that programmers know what they are doing; it only requires that they state their intentions explicitly. 116 | 117 | C, like any other language, has its blemishes. Some of the operators have the wrong precedence; some parts of the syntax could be better. Nonetheless, C has proven to be an extremely effective and expressive language for a wide variety of programming applications. 118 | 119 | The book is organized as follows. Chapter 1 is a tutorial on the central part of C. The purpose is to get the reader started as quickly as possible, since we believe strongly that the way to learn a new language is to write programs in it. The tutorial does assume a working knowledge of the basic elements of programming; there is no explanation of computers, of compilation, nor of the meaning of an expressionlike n=n+ 1. Although we have tried where possibleto show useful programming techniques, the book is not intended to be a reference work on data structures and algorithms; when forced to make a choice, we have Concentratedon the language. 120 | 121 | Chapters 2 through 6 discuss various aspects of C in more detail, and rather more formally, than does Chapter 1, although the emphasis is still on examples of complete programs, rather than isolated fragments. Chapter 2 deals with the basic data types, operators and expressions. Chapter 3 treats control flow: if-else, switcb,while,for, etc. Chapter4coversfunctionsandprogram structure-external variables, scope rules, multiple source files, and so on-and also touches on the preprocessor. Chapter 5 discusses pointers and address arithmetic. Chapter 6 covers structures and unions. 122 | 123 | Chapter 7 describes the standard library, which provides a common interface to the operating system. This library is defined by the ANSI standard and is meant to be supported on all machines that support C, so programs that use it for input, output, and other operating system access can be moved from one system to another without change. 124 | 125 | Chapter 8 describes an interface between C programs and the UNIX operating system, concentrating on input/output, the file system, and storage allocation. Although some of this chapter is specific to UNIX systems, programmers who use other systems should still find useful material here, including some insight into how one version of the standard library is implemented, and suggestions on portability. 126 | 127 | Appendix A contains a language reference manual. The official statement of the syntax and semantics of C is the ANSI standard itself. That document, however, is intended foremost for compiler writers. The reference manual here conveys the definition of the language more concisely and without the same legalistic style. Appendix B is a summary of the standard library, again for users rather than implementers. Appendix C is a short summary of changes from the original language. In cases of doubt, however, the standard and one's own compiler remain the final authorities on the language. 128 | 129 | ## Chapter 1. A Tutorial Introduction 130 | 131 | ## Chapter 2. Types, Operators, and Expressions 132 | 133 | ## Chapter 3. Control Flow 134 | 135 | ## Chapter 4. Functions and Program Structure 136 | 137 | ## Chapter 5. Pointers and Array 指针与数组 138 | 139 | A pointer is a variable that contains the address of a variable. Pointers are much used in C, partly because they are sometimes the only way to express a computation, and partly because they usually lead to more compact and efficient code than can be obtained in other ways. Pointers and arrays are closely related; this chapter also explores this relationship and shows how to exploit it. 140 | 141 | 指针是一种保存变量地址的变量。在 C 语言中,指针的使用非常广泛,原因之一是,指针常常是表达某个计算的惟一途径,另一个原因是,同其它方法比较起来,使用指针通常可以生成更高效、更紧凑的代码。指针与数组之间的关系十分密切,我们将在本章中讨论它们之间的关系,并探讨如何利用这种关系。 142 | 143 | Pointers have been lumped with the goto statement as a marvelous way to create impossibleto-understand programs. This is certainly true when they are used carelessly, and it is easy to create pointers that point somewhere unexpected. With discipline, however, pointers can also be used to achieve clarity and simplicity. This is the aspect that we will try to illustrate. 144 | 145 | 指针和 goto 语句一样,会导致程序难以理解。如果使用者粗心,指针很容易就指向了错误的地方。但是,如果谨慎地使用指针,便可以利用它写出简单、清晰的程序。在本章中我们将尽力说明这一点。 146 | 147 | The main change in ANSI C is to make explicit the rules about how pointers can be manipulated, in effect mandating what good programmers already practice and good compilers already enforce. In addition, the type void * (pointer to void) replaces char * as the proper type for a generic pointer. 148 | 149 | ANSI C 的一个最重要的变化是,它明确地制定了操纵指针的规则。事实上,这些规则已经被很多优秀的程序设计人员和编译器所采纳。此外,ANSI C 使用类型 `void *`(指向 void 的指针)代替 `char *` 作为通用指针的类型。 150 | 151 | ### 5.1 Pointers and Addresses 指针与地址 152 | 153 | Let us begin with a simplified picture of how memory is organized. A typical machine has an array of consecutively numbered or addressed memory cells that may be manipulated individually or in contiguous groups. One common situation is that any byte can be a char, a pair of one-byte cells can be treated as a short integer, and four adjacent bytes form a long. A pointer is a group of cells (often two or four) that can hold an address. So if c is a char and p is a pointer that points to it, we could represent the situation this way: 154 | 155 | 首先,我们通过一个简单的示意图来说明内存是如何组织的。通常的机器都有一系列连续编号或编址的存储单元,过些存储单元可以单个进行操纵,也可以以连续成组的方式操纵。 通常情况下,机器的一个字节可以存放一个 char 类型的数据,两个相邻的字节存储单元可存储 1 个 short(短整型)类型的数据,而 4 个相邻的字节存储单元可存储 1 个 long(长整型)类型的数据。指针是能够存放一个地址的一组存储单元(通常是 2 个或 4 个字节)。因此,如果 c 的类型是 char,并且 p 是指向 c 的指针,则可用图 5-1 表示它们之间的关系: 156 | 157 | ![](TCPL-5-1.png) 158 | 159 | ---- 160 | The unary operator & gives the address of an object, so the statement 161 | 162 | 一元运算符 & 可用于取一个对象的地址,因此,下列语句 163 | 164 | ``` C 165 | p = &c; 166 | ``` 167 | 168 | assigns the address of c to the variable p, and p is said to 'point to' c. The & operator only applies to objects in memory: variables and array elements. It cannot be applied to expressions, constants, or register variables. 169 | 170 | 将把 c 的地址赋值给变量 p,我们称 p 为指向 c 的指针。地址运算符 & 只能应用于内存中的对象,即变量与数组元素。它不能作用于表达式、常量或 register 类型的变量。 171 | 172 | ---- 173 | The unary operator * is the indirection or dereferencing operator; when applied to a pointer, it accesses the object the pointer points to. Suppose that x and y are integers and ip is a pointer to int. This artificial sequence shows how to declare a pointer and how to use & and *: 174 | 175 | 一元运算符 * 是间接寻址或间接引用运算符。当它作用于指针时,将访问指针所指向的对象。我们在这里假定 x 与 y 是整数,而 ip 是指向 int 类型的指针,下面的代码段说明了如何在程序中声明指针以及如何使用运算符 & 和 *: 176 | 177 | ``` C 178 | int x = 1, y = 2, z[10]; 179 | int *ip; /* ip is a pointer to int */ 180 | ip = &x; /* ip now points to x */ 181 | y = *ip; /* y is now 1 */ 182 | *ip = 0; /* x is now 0 */ 183 | ip = &z[0]; /* ip now points to z[0] */ 184 | ``` 185 | 186 | The declaration of x, y, and z are what we've seen all along. The declaration of the pointer ip, 187 | 188 | 变量 x、y 与 z 的声明方式我们已经在前面的章节中见到过。我们来看指针 ip 的声明,如下所示: 189 | ``` C 190 | int *ip; 191 | ``` 192 | is intended as a mnemonic; it says that the expression *ip is an int. The syntax of the declaration for a variable mimics the syntax of expressions in which the variable might appear. This reasoning applies to function declarations as well. For example, 193 | 194 | 这样声明是为了便于记忆。该声明语句表明表达式 *ip 的结果是 int 类型。这种声明变量的语法与声明该变量所在表达式的语法类似。同样的原因,对函数的声明也可以采用这种方式。例如,声明 195 | ``` C 196 | double *dp, atof(char *); 197 | ``` 198 | says that in an expression *dp and atof(s) have values of double, and that the argument of atof is a pointer to char. 199 | 200 | 表明,在表达式中,*dp 和 atof(s) 的值都是 double 类型,且 atof 的参数是一个指向 char 类型的指针。 201 | 202 | You should also note the implication that a pointer is constrained to point to a particular kind of object: every pointer points to a specific data type. (There is one exception: a 'pointer to void' is used to hold any type of pointer but cannot be dereferenced itself. We'll come back to it in Section 5.11.) 203 | 204 | 我们应该注意,指针只能指向某种特定类型的对象,也就是说,每个指针都必须指向某种特定的数据类型。(一个例外情况是指向 void 类型的指针可以存放指向任何类型的指针,但它不能间接引用其自身。我们将在 5.11 节中详细讨论该问题)。 205 | 206 | If ip points to the integer x, then *ip can occur in any context where x could, so 207 | ``` C 208 | // 如果指针 ip 指向整型变量,那么在 x 可以出现的任何上下文中都可以使用 *ip,因此,语句将把 *ip 的值增加 10 209 | ip = *ip + 10; 210 | ``` 211 | increments *ip by 10. 212 | 213 | The unary operators * and & bind more tightly than arithmetic operators, so the assignment 214 | ``` C 215 | // 一元运算符 * 和 & 的优先级比算术运算符的优先级高,因此,赋值语句将把 *ip 指向的对象的值取出并加 1,然后再将结果赋值给 y 216 | y = *ip + 1; 217 | ``` 218 | takes whatever ip points at, adds 1, and assigns the result to y, while 219 | ``` C 220 | // 将 ip 指向的对象的值加 1 221 | *ip += 1; 222 | ``` 223 | increments what ip points to, as do 224 | ``` C 225 | ++*ip; 226 | ``` 227 | and 228 | ``` C 229 | (*ip)++; 230 | ``` 231 | 232 | The parentheses are necessary in this last example; without them, the expression would increment ip instead of what it points to, because unary operators like * and ++ associate right to left. 233 | 234 | 语句 (* ip)++ 中的圆括号是必需的,否则,该表达式将对 ip 进行加 1 运算, 而不是对 ip 指向的对象进行加 1 运算,这是因为,类似于 * 和 ++ 这样的一元运算符遵循从右至左的结合顺序。 235 | 236 | ---- 237 | Finally, since pointers are variables, they can be used without dereferencing. For example, if iq is another pointer to int, 238 | 239 | 最后说明一点,由于指针也是变量,所以在程序中可以直接使用,而不必通过间接引用的方法使用。例如,如果 iq 是另一个指向整型的指针,那么语句 240 | 241 | ``` C 242 | iq = ip; 243 | ``` 244 | 245 | copies the contents of ip into iq, thus making iq point to whatever ip pointed to. 246 | 247 | 将把 ip 中的值拷贝到 iq 中,这样,指针 iq 也将指向 ip 指向的对象。 248 | 249 | ### 5.2 Pointers and Function Arguments 指针与函数参数 250 | 251 | ## Chapter 6. Structures 252 | 253 | ## Chapter 7. Input and Output 254 | 255 | ## Chapter 8. The UNIX System Interface 256 | 257 | ## Appendix A. Reference Manual 258 | 259 | ## Appendix B. Standard Library 260 | 261 | ## Appendix C. Summary of Changes -------------------------------------------------------------------------------- /C++.md: -------------------------------------------------------------------------------- 1 | # C++ 2 | 3 | ## 参考资料 4 | 5 | ### 书籍 6 | - [《C++ Primer》](https://book.douban.com/subject/1767741/) by Stanley B.Lippman, Josée LaJoie, Barbara E.Moo 7 | - [《Effective C++》](https://book.douban.com/subject/5387403/) by Scott Meyers 8 | - [《More Effective C++》](https://book.douban.com/subject/5908727/) by Scott Meyers 9 | - [《Exceptional C++》](https://book.douban.com/subject/10785602/) by Herb Sutter 10 | - [《More Exceptional C++》](https://book.douban.com/subject/5908728/) by Herb Sutter 11 | - [《深度探索C++对象模型》](https://book.douban.com/subject/10427315/) by Stanley B.Lippman (著) / 侯捷 (译) 12 | - [《Effective STL》](https://book.douban.com/subject/24534868/) by Scott Meyers 13 | - [《STL源码剖析》](https://book.douban.com/subject/1110934/) by 侯捷 14 | 15 | ### 文章 16 | - [如何学好C++语言](http://coolshell.cn/articles/4119.html) by 陈皓 CoolShell 17 | - [“21天教你学会C++”](http://coolshell.cn/articles/2250.html) by 陈皓 CoolShell 18 | - [C++程序员自信心曲线图](http://coolshell.cn/articles/2287.html) by 陈皓 CoolShell 19 | - [恐怖的C++语言](http://coolshell.cn/articles/1724.html) by 陈皓 CoolShell 20 | - [C++的STD::STRING的“读时也拷贝”技术!](http://coolshell.cn/articles/1443.html) by Neo CoolShell 21 | -------------------------------------------------------------------------------- /C.md: -------------------------------------------------------------------------------- 1 | # C 语言 2 | 3 | 目录 4 | - [一、如何学习 C 语言](#一如何学习-c-语言) 5 | - [第一阶段:搭建开发环境](#第一阶段搭建开发环境) 6 | - [第二阶段:熟悉基本语法](#第二阶段熟悉基本语法) 7 | - [第三阶段:掌握常用的标准库函数](#第三阶段掌握常用的标准库函数) 8 | - [第四阶段:深入理解指针和内存管理](#第四阶段深入理解指针和内存管理) 9 | - [第五阶段:算法与数据结构](#第五阶段算法与数据结构) 10 | - [第六阶段:系统编程](#第六阶段系统编程) 11 | - [第七阶段:系统设计](#第七阶段系统设计) 12 | - [二、make 与 makefile](#二make-与-makefile) 13 | - [参考资料](#参考资料) 14 | 15 | ## 一、如何学习 C 语言 16 | 17 | 推荐先阅读陈皓的[如何学好C语言](http://coolshell.cn/articles/4102.html)这篇文章,作者已经给出了非常好的建议。我会在此基础上进行细化与补充。 18 | 19 | ### 第一阶段:搭建开发环境 20 | 21 | 我最推荐的方案是:macOS + Xcode 22 | 23 | #### 开发环境需要包括什么 24 | - 操作系统(这里指的是你写代码的工作环境而不是你所写程序的运行环境) 25 | - macOS(推荐) 26 | - Windows 27 | - 文本编辑器 28 | - 编译器 29 | - GCC 30 | - Clang 31 | - 调试器(非必需) 32 | - gdb 33 | - lldb 34 | - 构建工具(非必需) 35 | - make 36 | 37 | #### 什么是 IDE 38 | IDE,全称 Integrated Development Environment,即集成开发环境,它是文本编辑器、编译器、调试器等组件的集合。常用的支持 C 语言开发的 IDE 有: 39 | - macOS 环境 40 | - Xcode 41 | - CodeRunner(收费) 42 | - Windows 环境 43 | - Visual Studio 44 | - 跨平台 45 | - Eclipse IDE for C/C++ 46 | 47 | #### DIY 开发环境(不建议新手这样做,老实用 IDE 就好了) 48 | 49 | 如果你不喜欢 IDE,比如你不喜欢 Xcode 的文本编辑器想用 Vim,而 Xcode 的 Vim 插件又用着不爽。这时你可能需要搭建一个可以高度自定义的开发环境。 50 | - 方案一 51 | - 操作系统:macOS 52 | - 终端:iTerm2 + oh-my-zsh 53 | - 文本编辑器:Vim 54 | - 编译器:Clang 55 | - 构建工具:make 56 | 57 | ### 第二阶段:熟悉基本语法 58 | 59 | C 语言的语法不算复杂,建议快速的过一遍,现阶段做到大致了解,能够看懂别人写的示例程序即可。关于学习资料: 60 | - 如果你习惯看书,这一阶段建议看[《C程序设计语言》](https://book.douban.com/subject/1139336/)这一本就可以了,C 语言之父编写的书,几乎是学习 C 语言必读的。这类经典的书比较适合精度,随着你经验慢慢积累水平不断提高 ,需要时不时拿出来温习,温故而知新。 61 | - 如果你的英文水平尚可,我再推荐一个英文在线教程 [C Tutorial](https://www.tutorialspoint.com/cprogramming/index.htm),内容比较浅,每一章节篇幅都很短,适合快速阅读。 62 | - 此外,[C reference](http://en.cppreference.com/w/c) 和 [Standard C++ Library reference](http://www.cplusplus.com/reference/) 可以当做手册来查阅。 63 | 64 | #### C 程序的组成 65 | 66 | C 程序一般包含以下部分: 67 | - 预编译指令(Preprocessor Commands) 68 | - 变量(Variables) 69 | - 函数(Functions) 70 | - 语句(Statements) 71 | - 表达式(Expressions) 72 | - 结构(Structure) 73 | - 注释(Comments) 74 | 75 | #### Hello World 76 | 77 | 我们先来看一段简单的代码,它的运行结果就是在控制台输出 `Hello, World!`: 78 | ``` C 79 | #include 80 | 81 | int main(int argc, const char * argv[]) 82 | { 83 | /* my first program in C */ 84 | const char * str = "Hello, World!\n"; 85 | printf("%s", str); 86 | 87 | return 0; 88 | } 89 | ``` 90 | 91 | Xcode 8 环境执行结果: 92 | ``` 93 | Hello, World! 94 | Program ended with exit code: 0 95 | ``` 96 | 97 | 简单解释一下: 98 | - `#include` 是一个预编译指令,表示引入 `stdio.h` 这个头文件。 99 | - `int main () { ... }` 是一个函数,`{}` 中括起来的部分就是函数具体做的事情。`main` 函数是所有 C 程序的入口函数,它有两个参数 `argc` 和 `argv`。这两参数现阶段还用不到,暂时不做解释。 100 | - `/* my first program in C */` 是注释,不会影响程序的运行结果。 101 | - `str` 是变量,这里表示一个字符串,字符串的内容是“Hello, World!\n”。`\n` 是换行符。 102 | - `const char * str = "Hello, World!\n";` 是一个语句,语句必须用 `;` 分割。 103 | - `printf` 也是一个函数,其功能就是在控制台输出文本。 104 | 105 | ### 第三阶段:掌握常用的标准库函数 106 | 107 | C 标准库(C standard library,也称 libc)定义了那些我们在写 C 程序时可以直接调用的函数,例如 `printf()` 函数。这些标准库函数被定义在了若干个 `.h` 头文件中。那么问题来了,标准库函数究竟有哪些呢?事实上,这和你选择哪种 C 标准来写代码有关系。所谓的标准其实就是一种规范,只有大家都遵守统一规范才能保证你写的程序可以在别人的机器上正确的运行。而 C 语言是一门相当古老的编程语言,随着时间的推移,它的规范也在不断的改进和扩充。 108 | 109 | #### C 标准 110 | 111 | 不同标准的 C 语言会有不同数量的标准库函数。截止到目前,主要的 C 语言标准有: 112 | - ANSI C / C89 / C90 113 | - assert.h 114 | - ctype.h 115 | - errno.h 116 | - float.h 117 | - iso646.h 118 | - limits.h 119 | - locale.h 120 | - math.h 121 | - setjmp.h 122 | - signal.h 123 | - stdarg.h 124 | - stddef.h 125 | - stdio.h 126 | - stdlib.h 127 | - string.h 128 | - time.h 129 | - wchar.h 130 | - wctype.h 131 | - C99 132 | - complex.h 133 | - fenv.h 134 | - stdbool.h 135 | - stdint.h 136 | - tgmath.h 137 | - C11 138 | - stdalign.h 139 | - stdatomic.h 140 | - stdnoreturn.h 141 | - threads.h 142 | - uchar.h 143 | 144 | 现阶段主要需要熟悉 ANSI C 标准库函数。 145 | 146 | #### C POSIX library 147 | C POSIX library 是 C 语言的 POSIX 系统下的标准库。包含了一些在 C 语言标准库之外的函数。 148 | 149 | > POSIX( Portable Operating System Interface)是 IEEE 制定的一套标准,定义了操作系统应该为应用程序提供的接口标准。最初设计这套标准的目的是为了提高类 UNIX 环境下应用程序的可移植性。 150 | 151 | #### The GNU C Library (glibc) 152 | C 标准库的开源实现。 153 | 154 | ### 第四阶段:深入理解指针和内存管理 155 | 156 | #### 栈内存 157 | - 编译器自动管理(分配与释放) 158 | - 从高地址开始分配,下开口栈,后进先出 159 | - 最大上限预先设置,可能会溢出 160 | 161 | ``` C 162 | #include 163 | 164 | int main(int argc, const char * argv[]) 165 | { 166 | char a = 'a'; // char 占 1 字节 167 | char b = 'b'; 168 | printf("%p\n", &a); // 0x7fff5fbff7e7 169 | printf("%d\n", a); // 97 170 | printf("%p\n", &b); // 0x7fff5fbff7e6 171 | printf("%d\n", b); // 98 172 | return 0; 173 | } 174 | ``` 175 | 176 | 变量 | 地址 | 值 177 | ---- | ---- | ---- 178 | a | 0x7fff5fbff7e7 | 0110 0001 179 | b | 0x7fff5fbff7e6 | 0110 0010 180 | 181 | ``` C 182 | #include 183 | 184 | int main(int argc, const char * argv[]) 185 | { 186 | int a = 'a'; // int 占 4 字节 187 | int b = 'b'; 188 | printf("%p\n", &a); // 0x7fff5fbff7ec 189 | printf("%d\n", a); // 97 190 | printf("%p\n", &b); // 0x7fff5fbff7e8 191 | printf("%d\n", b); // 98 192 | return 0; 193 | } 194 | ``` 195 | 196 | 变量 | 地址 | 值 197 | ---- | ---- | ---- 198 | a | 0x7fff5fbff7ec | 0110 0001 199 | | 0x7fff5fbff7eb | 0000 0000 200 | | 0x7fff5fbff7ea | 0000 0000 201 | | 0x7fff5fbff7e9 | 0000 0000 202 | b | 0x7fff5fbff7e8 | 0110 0010 203 | | 0x7fff5fbff7e7 | 0000 0000 204 | | 0x7fff5fbff7e6 | 0000 0000 205 | | 0x7fff5fbff7e5 | 0000 0000 206 | 207 | 函数中局部变量占用的内存,在函数返回后会被回收 208 | ``` C 209 | #include 210 | 211 | void test() 212 | { 213 | char a = 'a'; 214 | char b = 'b'; 215 | printf("%p\n", &a); 216 | printf("%d\n", a); 217 | printf("%p\n", &b); 218 | printf("%d\n", b); 219 | } 220 | 221 | int main(int argc, const char * argv[]) 222 | { 223 | test(); 224 | test(); 225 | 226 | return 0; 227 | } 228 | 229 | 输出结果: 230 | 0x7fff5fbff7df 231 | 97 232 | 0x7fff5fbff7de 233 | 98 234 | 0x7fff5fbff7df 235 | 97 236 | 0x7fff5fbff7de 237 | 98 238 | ``` 239 | 上述示例说明函数内的局部变量 `a` 和 `b` 在函数返回后就被回收了,`0x7fff5fbff7df` 和 `0x7fff5fbff7de` 这两块内存被循环使用了。 240 | 241 | #### 堆内存 242 | - 调用 `malloc` 等函数手动申请,调用 `free` 手动释放 243 | 244 | 64 位编译器下,各数据类型所占字节大小。 245 | ``` C 246 | int main(int argc, const char * argv[]) 247 | { 248 | printf("%lu\n", sizeof(char)); // 1 249 | printf("%lu\n", sizeof(int)); // 4 250 | printf("%lu\n", sizeof(float)); // 4 251 | printf("%lu\n", sizeof(double)); // 8 252 | printf("%lu\n", sizeof(short)); // 2 253 | printf("%lu\n", sizeof(long)); // 8 254 | printf("%lu\n", sizeof(long long)); // 8 255 | printf("%lu\n", sizeof(void *)); // 8 256 | 257 | return 0; 258 | } 259 | ``` 260 | > 注:sizeof 是一个运算符而不是函数,编译器在编译时就计算出了 sizeof 的结果。 261 | 262 | ``` C 263 | int main(int argc, const char * argv[]) 264 | { 265 | void * a = malloc(1 * sizeof(char)); // 指针占 8 字节 266 | void * b = malloc(4 * sizeof(char)); 267 | void * c = malloc(1 * sizeof(char)); 268 | void * d = malloc(2 * sizeof(char)); 269 | 270 | printf("%p\n", &a); // 0x7fff5fbff7e8 271 | printf("%p\n", &b); // 0x7fff5fbff7e0 272 | printf("%p\n", &c); // 0x7fff5fbff7d8 273 | printf("%p\n", &d); // 0x7fff5fbff7d0 274 | 275 | printf("%p\n", a); // 0x100700000 276 | printf("%p\n", b); // 0x100700010 277 | printf("%p\n", c); // 0x100700020 278 | printf("%p\n", d); // 0x100700030 279 | 280 | return 0; 281 | } 282 | ``` 283 | 284 | #### 函数调用与函数指针 285 | 286 | ### 第五阶段:算法与数据结构 287 | 288 | ### 第六阶段:系统编程 289 | 290 | ### 第七阶段:系统设计 291 | 292 | ## 二、make 与 makefile 293 | 294 | - [GNU Make Manual](https://www.gnu.org/software/make/manual/make.html) 295 | - [跟我一起写 Makefile](http://blog.csdn.net/haoel/article/details/2886) by 陈皓 2004 296 | 297 | ## 参考资料 298 | ### 站点 299 | - [C Tutorial](https://www.tutorialspoint.com/cprogramming/index.htm) 300 | - [C reference](http://en.cppreference.com/w/c) 301 | - [Standard C++ Library reference](http://www.cplusplus.com/reference/) 302 | 303 | ### 书籍 304 | - [《C程序设计语言》](https://book.douban.com/subject/1139336/) by Brian W. Kernighan, Dennis M. Ritchie 305 | - [《C和指针》](https://book.douban.com/subject/3012360/) by Kenneth A.Reek 306 | - [《C专家编程》](https://book.douban.com/subject/2377310/) by Peter Van Der Linden 307 | - [《C陷阱与缺陷》](https://book.douban.com/subject/2778632/) by Andrew Koenig 308 | 309 | ### 文章 310 | - [如何学好C语言](http://coolshell.cn/articles/4102.html) by CoolShell 陈皓 2011 311 | - [深入理解C语言](http://coolshell.cn/articles/5761.html) by CoolShell 陈皓 2011 312 | - [C语言的演变史](http://coolshell.cn/articles/1984.html) by CoolShell 陈皓 2009 313 | - [C语言-内存管理基础](http://www.jianshu.com/p/b2380e47d005) by 简书 CoderYQ 2017 314 | - [C语言-内存管理深入](http://www.jianshu.com/p/ccb337572498) by 简书 CoderYQ 2017 315 | - [Learn to Read Dissasembly for Fun and Profit](http://www.jeremyong.com/blog/2014/10/26/learn-to-read-dissasembly-for-fun-and-profit/) by /dev/something 2014 316 | -------------------------------------------------------------------------------- /Cache.md: -------------------------------------------------------------------------------- 1 | # 缓存 2 | 3 | 分类: 4 | - 内存缓存 MemoryCache 5 | - 磁盘缓存 DiskCache 6 | 7 | 思考: 8 | - 如何保证线程安全 9 | - 如何实现淘汰算法 10 | - 如何评估性能 11 | 12 | ## 参考 13 | - [YYCache](https://github.com/ibireme/YYCache) | [YYCache 设计思路](https://blog.ibireme.com/2015/10/26/yycache/) by ibireme 14 | - [KTVHTTPCache](https://github.com/ChangbaDevs/KTVHTTPCache) - 唱吧 iOS 音视频缓存处理框架 -------------------------------------------------------------------------------- /Compression.md: -------------------------------------------------------------------------------- 1 | # 压缩 2 | 3 | ## 1. 压缩原理 4 | 5 | > 压缩原理其实很简单,就是找出那些重复出现的字符串,然后用更短的符号代替,从而达到缩短字符串的目的。比如,有一篇文章大量使用"中华人民共和国"这个词语,我们用"中国"代替,就缩短了5个字符,如果用"华"代替,就缩短了6个字符。事实上,只要保证对应关系,可以用任意字符代替那些重复出现的字符串。 6 | > 7 | > 本质上,所谓"压缩"就是找出文件内容的概率分布,将那些出现概率高的部分代替成更短的形式。所以,内容越是重复的文件,就可以压缩地越小。比如,"ABABABABABABAB"可以压缩成"7AB"。 8 | > 9 | > 相应地,如果内容毫无重复,就很难压缩。极端情况就是,遇到那些均匀分布的随机字符串,往往连一个字符都压缩不了。比如,任意排列的10个阿拉伯数字(5271839406),就是无法压缩的;再比如,无理数(比如π)也很难压缩。 10 | > 11 | > 压缩就是一个消除冗余的过程,相当于用一种更精简的形式,表达相同的内容。可以想象,压缩过一次以后,文件中的重复字符串将大幅减少。好的压缩算法,可以将冗余降到最低,以至于再也没有办法进一步压缩。所以,压缩已经压缩过的文件(递归压缩),通常是没有意义的。 12 | > 13 | > (摘自[数据压缩与信息熵](http://www.ruanyifeng.com/blog/2014/09/information-entropy.html) by 阮一峰 2014) 14 | 15 | ## 2. Huffman 16 | - [HUFFMAN 编码压缩算法](https://coolshell.cn/articles/7459.html) by 陈皓 2012 17 | 18 | ## 3. LZ77 19 | 20 | ## 4. zlib 21 | 22 | ### 4.1. Deflate Algorithm 23 | 24 | ## 5. zstd 25 | 26 | ## 6. 图片压缩 27 | 28 | ## 7. References 29 | - [zlib](http://www.zlib.net) 30 | - [zstd](https://github.com/facebook/zstd) - Fast real-time compression algorithm. -------------------------------------------------------------------------------- /DNS.md: -------------------------------------------------------------------------------- 1 | # 深入理解 DNS 2 | 3 | ## dig 4 | ``` 5 | $ dig www.aliyun.com 6 | 7 | ; <<>> DiG 9.8.3-P1 <<>> www.aliyun.com 8 | ;; global options: +cmd 9 | ;; Got answer: 10 | ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42772 11 | ;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 0 12 | 13 | ;; QUESTION SECTION: 14 | ;www.aliyun.com. IN A 15 | 16 | ;; ANSWER SECTION: 17 | www.aliyun.com. 82 IN CNAME www-jp-de-intl-adns.aliyun.com. 18 | www-jp-de-intl-adns.aliyun.com. 262 IN CNAME www-jp-de-intl-adns.aliyun.com.gds.alibabadns.com. 19 | www-jp-de-intl-adns.aliyun.com.gds.alibabadns.com. 119 IN CNAME wagbridge.aliyun.com. 20 | wagbridge.aliyun.com. 232 IN CNAME sh.wagbridge.aliyun.com. 21 | sh.wagbridge.aliyun.com. 232 IN CNAME sh.wagbridge.aliyun.com.gds.alibabadns.com. 22 | sh.wagbridge.aliyun.com.gds.alibabadns.com. 119 IN A 140.205.32.8 23 | 24 | ;; Query time: 158 msec 25 | ;; SERVER: 192.168.1.234#53(192.168.1.234) 26 | ;; WHEN: Mon Feb 5 14:52:33 2018 27 | ;; MSG SIZE rcvd: 210 28 | ``` 29 | 30 | ## Ref 31 | - [DNS 原理入门](http://www.ruanyifeng.com/blog/2016/06/dns.html) by 阮一峰 2016 -------------------------------------------------------------------------------- /DesignPattern.md: -------------------------------------------------------------------------------- 1 | # 设计模式 Design Pattern 2 | 3 | ## 1. 六大原则 4 | 5 | ### 1.1. 开闭原则(Open Close Principle) 6 | 7 | ### 1.2. 里氏代换原则(Liskov Substitution Principle) 8 | 9 | ### 1.3. 依赖倒转原则(Dependence Inversion Principle) 10 | 11 | ### 1.4. 接口隔离原则(Interface Segregation Principle) 12 | 13 | ### 1.5. 最少知道原则(Demeter Principle) 14 | 15 | ### 1.6. 合成复用原则(Composite Reuse Principle) 16 | 17 | ## 2. 五种创建模式 18 | 19 | ### 2.1. 工厂方法(Factory Method) 20 | 21 | ### 2.2. 抽象工厂(Abstract Factory) 22 | 23 | ### 2.3. 单例模式(Singleton) 24 | 25 | ### 2.4. 建造者模式(Builder) 26 | 27 | ### 2.5. 原型模式(Prototype) 28 | 29 | ## 3. 七种结构模式 30 | 31 | ## 4. 十一种行为模式 32 | 33 | ## 5. Ref 34 | - [《设计模式 -- 可复用面向对象软件的基础》](https://book.douban.com/subject/1052241/) 35 | - [《Head First 设计模式》](https://book.douban.com/subject/2243615/) 36 | - [从面向对象的设计模式看软件设计](https://coolshell.cn/articles/8961.html) by 陈皓 2013 -------------------------------------------------------------------------------- /ES6.md: -------------------------------------------------------------------------------- 1 | # ES6 2 | 3 | ## 1. 关于 ES6 4 | ES6 泛指 ES5.1 版本以后的 ECMAScript 标准,包括 ES2015、ES2016、ES2017。2015 年开始标准委员会决定标准在每年六月正式发布一次,作为当年的正式版本。 5 | 6 | ## 2. 字符串 7 | 8 | ### 2.1. 模板字面量 Template Literals 9 | 10 | ## 3. 集合类型 11 | 12 | ### 3.1. Array 13 | 14 | ### 3.2. Set 15 | 16 | ### 3.3. Map 17 | 18 | ## 4. 错误处理 Error Handling 19 | 20 | ## 5. ES 编程风格 21 | - [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript) | [中文版](https://github.com/sivan/javascript-style-guide) 22 | - [ESLint](https://github.com/eslint/eslint) 23 | - plugin 24 | - [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react) 25 | - config 26 | - [Airbnb's base JS ESLint config, following our styleguide](https://github.com/airbnb/javascript) 27 | - [Airbnb's ESLint config, following our styleguide](https://github.com/airbnb/javascript) 28 | - [Google ESLint 规则](https://github.com/google/eslint-config-google) 29 | - [AlloyTeam ESLint 规则](https://github.com/AlloyTeam/eslint-config-alloy) 30 | - [饿了么前端 ESLint 规则](https://github.com/ElemeFE/eslint-config-elemefe) 31 | 32 | ## 6. 参考资料 33 | - [ECMAScript 6 入门](http://es6.ruanyifeng.com/#docs/intro) by 阮一峰 -------------------------------------------------------------------------------- /GCD.md: -------------------------------------------------------------------------------- 1 | # Grand Central Dispatch(GCD) 2 | 3 | 4 | 5 | - [1. 背景知识](#1-背景知识) 6 | - [1.1. 什么是线程安全?](#11-什么是线程安全) 7 | - [2. 概念](#2-概念) 8 | - [3. GCD 中的三种队列](#3-gcd-中的三种队列) 9 | - [4. dispatch_queue_create 创建队列](#4-dispatch_queue_create-创建队列) 10 | - [5. dispatch_once](#5-dispatch_once) 11 | - [5.1. dispatch_once 导致死锁](#51-dispatch_once-导致死锁) 12 | - [5.2. dispatch_once 源码解析](#52-dispatch_once-源码解析) 13 | - [6. dispatch_sync 同步提交任务](#6-dispatch_sync-同步提交任务) 14 | - [6.1. dispatch_sync 导致死锁](#61-dispatch_sync-导致死锁) 15 | - [7. dispatch_async 异步提交任务](#7-dispatch_async-异步提交任务) 16 | - [8. dispatch_barrier](#8-dispatch_barrier) 17 | - [9. dispatch_semaphore 信号量](#9-dispatch_semaphore-信号量) 18 | - [10. dispatch_group](#10-dispatch_group) 19 | - [11. dispatch_after 延迟提交](#11-dispatch_after-延迟提交) 20 | - [12. dispatch_apply 替代循环](#12-dispatch_apply-替代循环) 21 | - [13. dispatch_suspend & dispatch_resume 挂起和恢复派发队列或者派发源](#13-dispatch_suspend--dispatch_resume-挂起和恢复派发队列或者派发源) 22 | - [14. dispatch_block_cancel 取消任务](#14-dispatch_block_cancel-取消任务) 23 | - [15. dispatch_queue_set_specific & dispatch_get_specific](#15-dispatch_queue_set_specific--dispatch_get_specific) 24 | - [16. main thread 和 main queue 有什么区别?](#16-main-thread-和-main-queue-有什么区别) 25 | - [17. 如何判断当前队列是否是主队列?](#17-如何判断当前队列是否是主队列) 26 | - [17.1. 方法一:React Native 中的实现,使用 dispatch_queue_set_specific 和 dispatch_get_specific 来设置标志](#171-方法一react-native-中的实现使用-dispatch_queue_set_specific-和-dispatch_get_specific-来设置标志) 27 | - [17.2. 方法二:比对当前队列的 label 与主队列的 label 是否一致](#172-方法二比对当前队列的-label-与主队列的-label-是否一致) 28 | - [18. Dispatch Sources](#18-dispatch-sources) 29 | - [19. 参考资料](#19-参考资料) 30 | 31 | 32 | 33 | ## 1. 背景知识 34 | 35 | ### 1.1. 什么是线程安全? 36 | 线程安全指一段代码执行过程中不会有其他线程介入。[iOS 多线程到底不安全在哪里?](http://www.mrpeak.cn/blog/ios-thread-safety/) 37 | 38 | ## 2. 概念 39 | - Dispatch Queue 派发队列 40 | - Dispatch Source 派发源 41 | 42 | ## 3. GCD 中的三种队列 43 | - main queue:主队列,串行 44 | - global queue:全局队列,并行 45 | - custom queue:自定义队列,可以通过 dispatch_queue_create 函数创建 46 | 47 | ## 4. dispatch_queue_create 创建队列 48 | ``` C 49 | // Creates a new dispatch queue to which blocks can be submitted. 50 | dispatch_queue_t dispatch_queue_create(const char *label, dispatch_queue_attr_t attr); 51 | ``` 52 | - label 可以为空,也可以重复,为了方便调试需要自己确保其唯一性。可以通过 dispatch_queue_get_label() 函数获取到指定 queue 的 label,但不能通过 label 反查 queue。 53 | 54 | ``` C 55 | // 创建串行队列 56 | dispatch_queue_t queue = dispatch_queue_create("com.example.myqueue", DISPATCH_QUEUE_SERIAL); 57 | 58 | // 创建并行队列 59 | dispatch_queue_t queue = dispatch_queue_create("com.example.myqueue", DISPATCH_QUEUE_CONCURRENT); 60 | ``` 61 | 62 | 源码:[queue.c](https://github.com/apple/swift-corelibs-libdispatch/blob/master/src/queue.c) 63 | 64 | ## 5. dispatch_once 65 | 66 | ``` C 67 | // Executes a block object once and only once for the lifetime of an application. 68 | void dispatch_once(dispatch_once_t *token, dispatch_block_t block); 69 | ``` 70 | - dispatch_once 是 Objective-C 中实现单例模式的最佳方式,关于单例模式详见[这篇笔记](Singleton.md) 71 | - dispatch_once 是线程安全的,且性能优于 @synchronized 72 | - dispatch_once_t 类型变量必须是 global 或 static 的 73 | - dispatch_once 可能导致死锁 74 | 75 | ### 5.1. dispatch_once 导致死锁 76 | [原文链接](http://joeleee.github.io/2017/03/20/011.dispatch_once/) 77 | ``` Objective-C 78 | - (void)viewDidLoad { 79 | [super viewDidLoad]; 80 | [self once1]; 81 | } 82 | - (void)once1 { 83 | NSLog(@"Started dispatch_once1"); 84 | static dispatch_once_t onceToken; 85 | dispatch_once(&onceToken, ^{ 86 | [self once2]; 87 | }); 88 | NSLog(@"Finished dispatch_once1"); 89 | } 90 | - (void)once2 { 91 | NSLog(@"Started dispatch_once2"); 92 | static dispatch_once_t onceToken; 93 | dispatch_once(&onceToken, ^{ 94 | [self once1]; 95 | }); 96 | NSLog(@"Finished dispatch_once2"); 97 | } 98 | ``` 99 | 100 | ### 5.2. dispatch_once 源码解析 101 | 源码地址:[once.c](https://github.com/apple/swift-corelibs-libdispatch/blob/master/src/once.c) 102 | ``` 103 | // 调用过程 104 | dispatch_once → dispatch_once_f → dispatch_once_f_slow 105 | ``` 106 | 107 | _dispatch_once_waiter_t 结构体 108 | ``` C 109 | typedef struct _dispatch_once_waiter_s { 110 | volatile struct _dispatch_once_waiter_s *volatile dow_next; 111 | dispatch_thread_event_s dow_event; 112 | mach_port_t dow_thread; 113 | } *_dispatch_once_waiter_t; 114 | ``` 115 | 疑问: 116 | - struct _dispatch_once_waiter_s 为什么用 volatile 修饰? 117 | 118 | dispatch_once_f_slow 函数 119 | ``` C 120 | DISPATCH_ONCE_SLOW_INLINE 121 | static void 122 | dispatch_once_f_slow(dispatch_once_t *val, void *ctxt, dispatch_function_t func) 123 | { 124 | #if DISPATCH_GATE_USE_FOR_DISPATCH_ONCE 125 | dispatch_once_gate_t l = (dispatch_once_gate_t)val; 126 | 127 | if (_dispatch_once_gate_tryenter(l)) { 128 | _dispatch_client_callout(ctxt, func); 129 | _dispatch_once_gate_broadcast(l); 130 | } else { 131 | _dispatch_once_gate_wait(l); 132 | } 133 | #else 134 | _dispatch_once_waiter_t volatile *vval = (_dispatch_once_waiter_t*)val; 135 | struct _dispatch_once_waiter_s dow = { }; 136 | _dispatch_once_waiter_t tail = &dow, next, tmp; 137 | dispatch_thread_event_t event; 138 | 139 | if (os_atomic_cmpxchg(vval, NULL, tail, acquire)) { 140 | dow.dow_thread = _dispatch_tid_self(); 141 | _dispatch_client_callout(ctxt, func); 142 | 143 | next = (_dispatch_once_waiter_t)_dispatch_once_xchg_done(val); 144 | while (next != tail) { 145 | tmp = (_dispatch_once_waiter_t)_dispatch_wait_until(next->dow_next); 146 | event = &next->dow_event; 147 | next = tmp; 148 | _dispatch_thread_event_signal(event); 149 | } 150 | } else { 151 | _dispatch_thread_event_init(&dow.dow_event); 152 | next = *vval; 153 | for (;;) { 154 | if (next == DISPATCH_ONCE_DONE) { 155 | break; 156 | } 157 | if (os_atomic_cmpxchgv(vval, next, tail, &next, release)) { 158 | dow.dow_thread = next->dow_thread; 159 | dow.dow_next = next; 160 | if (dow.dow_thread) { 161 | pthread_priority_t pp = _dispatch_get_priority(); 162 | _dispatch_thread_override_start(dow.dow_thread, pp, val); 163 | } 164 | _dispatch_thread_event_wait(&dow.dow_event); 165 | if (dow.dow_thread) { 166 | _dispatch_thread_override_end(dow.dow_thread, val); 167 | } 168 | break; 169 | } 170 | } 171 | _dispatch_thread_event_destroy(&dow.dow_event); 172 | } 173 | #endif 174 | } 175 | ``` 176 | 177 | ## 6. dispatch_sync 同步提交任务 178 | ``` C 179 | // Submits a block object for execution on a dispatch queue and waits until that block completes. 180 | void dispatch_sync(dispatch_queue_t queue, dispatch_block_t block); 181 | ``` 182 | - 提交并执行一个任务,直到任务完成,才能提交下一个。 183 | - 无论是提交到串行队列还是并行队列 dispatch_sync 都不会开辟新的线程而是直接在当前线程中执行,因此会阻塞当前线程直到 block 执行完。 184 | - 什么场景下需要使用 dispatch_sync ?[You use it when you want to execute a block and wait for the results.](https://stackoverflow.com/questions/4607125/using-dispatch-sync-in-grand-central-dispatch) 185 | 186 | ``` C 187 | - (void)testDispatchSyncUseSerialQueue { 188 | dispatch_queue_t queue = dispatch_queue_create("com.example.myqueue", DISPATCH_QUEUE_SERIAL); 189 | dispatch_sync(queue, ^{ 190 | NSLog(@"current thread = %@", [NSThread currentThread]); // current thread = {number = 1, name = main} 191 | }); 192 | } 193 | 194 | - (void)testDispatchSyncUseConcurrentQueue { 195 | dispatch_queue_t queue = dispatch_queue_create("com.example.myqueue", DISPATCH_QUEUE_CONCURRENT); 196 | dispatch_sync(queue, ^{ 197 | NSLog(@"current thread = %@", [NSThread currentThread]); // current thread = {number = 1, name = main} 198 | }); 199 | } 200 | ``` 201 | 202 | ``` C 203 | - (void)testExample { 204 | dispatch_queue_t queue = dispatch_queue_create("com.example.myqueue", DISPATCH_QUEUE_SERIAL); 205 | for (NSInteger index = 0; index < 10; index++) { 206 | dispatch_async(queue, ^{ 207 | sleep(1); 208 | NSLog(@"index= %d, current thread = %@", index, [NSThread currentThread]); 209 | }); 210 | } 211 | dispatch_sync(queue, ^{ 212 | NSLog(@"end, current thread = %@", [NSThread currentThread]); 213 | }); 214 | } 215 | 216 | 运行结果: 217 | 2017-12-04 10:29:02.633794+0800 xctest[2523:516506] index= 0, current thread = {number = 2, name = (null)} 218 | 2017-12-04 10:29:03.637787+0800 xctest[2523:516506] index= 1, current thread = {number = 2, name = (null)} 219 | 2017-12-04 10:29:04.639562+0800 xctest[2523:516506] index= 2, current thread = {number = 2, name = (null)} 220 | 2017-12-04 10:29:05.644287+0800 xctest[2523:516506] index= 3, current thread = {number = 2, name = (null)} 221 | 2017-12-04 10:29:06.648002+0800 xctest[2523:516506] index= 4, current thread = {number = 2, name = (null)} 222 | 2017-12-04 10:29:07.653095+0800 xctest[2523:516506] index= 5, current thread = {number = 2, name = (null)} 223 | 2017-12-04 10:29:08.655106+0800 xctest[2523:516506] index= 6, current thread = {number = 2, name = (null)} 224 | 2017-12-04 10:29:09.658384+0800 xctest[2523:516506] index= 7, current thread = {number = 2, name = (null)} 225 | 2017-12-04 10:29:10.663733+0800 xctest[2523:516506] index= 8, current thread = {number = 2, name = (null)} 226 | 2017-12-04 10:29:11.668381+0800 xctest[2523:516506] index= 9, current thread = {number = 2, name = (null)} 227 | 2017-12-04 10:29:11.668592+0800 xctest[2523:516336] end, current thread = {number = 1, name = main} 228 | 229 | 如果这里换成异步队列,只会打印 end, current thread = {number = 1, name = main} 然后程序就结束了 230 | ``` 231 | 232 | ### 6.1. dispatch_sync 导致死锁 233 | 234 | 使用 dispatch_sync 向当前队列提交 block 必死锁 235 | ``` C 236 | - (void)viewDidLoad { 237 | dispatch_sync(dispatch_get_main_queue(), ^{ 238 | NSLog(@"I am block..."); 239 | }); 240 | } 241 | ``` 242 | 243 | ## 7. dispatch_async 异步提交任务 244 | ``` C 245 | // Submits a block for asynchronous execution on a dispatch queue and returns immediately. 246 | void dispatch_async(dispatch_queue_t queue, dispatch_block_t block); 247 | ``` 248 | - 提交任务后,不用等任务执行完,就可以提交下一个 249 | 250 | > dispatch_sync 和 dispatch_async 控制的是任务提交的过程,而队列类型控制的任务执行的过程。 251 | 252 | ## 8. dispatch_barrier 253 | ``` C 254 | // Submits a barrier block object for execution and waits until that block completes. 255 | void dispatch_barrier_sync(dispatch_queue_t queue, dispatch_block_t block); 256 | 257 | // Submits a barrier block for asynchronous execution and returns immediately. 258 | void dispatch_barrier_async(dispatch_queue_t queue, dispatch_block_t block); 259 | ``` 260 | - barrier 生效的基本条件是要在同一队列,因此在 global queue 中使用没有任何意义 261 | 262 | ## 9. dispatch_semaphore 信号量 263 | ``` C 264 | // Creates new counting semaphore with an initial value. 265 | dispatch_semaphore_t dispatch_semaphore_create(long value); 266 | 267 | // Signals, or increments, a semaphore. 268 | long dispatch_semaphore_signal(dispatch_semaphore_t dsema); 269 | 270 | // Waits for (decrements) a semaphore. 271 | // 返回 0 表示成功,返回非 0 表示超时 272 | long dispatch_semaphore_wait(dispatch_semaphore_t dsema, dispatch_time_t timeout); 273 | ``` 274 | 275 | ``` C 276 | - (void)testSemaphore 277 | { 278 | dispatch_semaphore_t doneSem = dispatch_semaphore_create(0); 279 | dispatch_queue_t queue = dispatch_queue_create("io.iamjiyixuan.queue", DISPATCH_QUEUE_SERIAL); 280 | // 1. 提交任务 281 | dispatch_async(queue, ^{ 282 | // 2. 模拟执行耗时网络请求 283 | sleep(5); 284 | dispatch_semaphore_signal(doneSem); 285 | }); 286 | // 3. 一直等待直到任务结束 287 | dispatch_semaphore_wait(doneSem, DISPATCH_TIME_FOREVER); 288 | // 或者设置超时时间为 30 秒 289 | // dispatch_semaphore_wait(doneSem, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC))); 290 | } 291 | ``` 292 | 293 | ## 10. dispatch_group 294 | ``` C 295 | // Creates a new group with which block objects can be associated. 创建失败返回 NULL 296 | dispatch_group_t dispatch_group_create(void); 297 | 298 | // Submits a block to a dispatch queue and associates the block with the specified dispatch group. 299 | void dispatch_group_async(dispatch_group_t group, dispatch_queue_t queue, dispatch_block_t block); 300 | 301 | // Schedules a block object to be submitted to a queue when a group of previously submitted block objects have completed. 302 | void dispatch_group_notify(dispatch_group_t group, dispatch_queue_t queue, dispatch_block_t block); 303 | 304 | // Waits synchronously for the previously submitted block objects to complete; returns if the blocks do not complete before the specified timeout period has elapsed. 305 | long dispatch_group_wait(dispatch_group_t group, dispatch_time_t timeout); 306 | 307 | // Explicitly indicates that a block has entered the group. 308 | void dispatch_group_enter(dispatch_group_t group); 309 | 310 | // Explicitly indicates that a block in the group has completed. 311 | void dispatch_group_leave(dispatch_group_t group); 312 | ``` 313 | 314 | ## 11. dispatch_after 延迟提交 315 | ``` C 316 | // Enqueue a block for execution at the specified time. 317 | void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block); 318 | ``` 319 | - 延迟提交,不是延迟执行 320 | 321 | ## 12. dispatch_apply 替代循环 322 | ``` C 323 | // Submits a block to a dispatch queue for multiple invocations. 324 | void dispatch_apply(size_t iterations, dispatch_queue_t queue, void (^block)(size_t)); 325 | ``` 326 | 327 | ## 13. dispatch_suspend & dispatch_resume 挂起和恢复派发队列或者派发源 328 | ``` C 329 | // Suspends the invocation of block objects on a dispatch object. 330 | void dispatch_suspend(dispatch_object_t object); 331 | 332 | // Resume the invocation of block objects on a dispatch object. 333 | void dispatch_resume(dispatch_object_t object); 334 | ``` 335 | 336 | ## 14. dispatch_block_cancel 取消任务 337 | > iOS 8 后 GCD 才支持对 dispatch block 的取消 338 | ``` C 339 | // Asynchronously cancels the specified dispatch block. 340 | void dispatch_block_cancel(dispatch_block_t block); 341 | ``` 342 | - 无法取消已经开始执行的 block 343 | 344 | ## 15. dispatch_queue_set_specific & dispatch_get_specific 345 | ``` C 346 | // Sets the key/value data for the specified dispatch queue. 347 | void dispatch_queue_set_specific(dispatch_queue_t queue, const void *key, void *context, dispatch_function_t destructor); 348 | 349 | // Returns the value for the key associated with the current dispatch queue. 350 | void * dispatch_get_specific(const void *key); 351 | ``` 352 | 353 | ## 16. main thread 和 main queue 有什么区别? 354 | 355 | - 每个 app 只能有一个 main thread 356 | - 可以通过 `[NSThread isMainThread]` 来判断当前线程是否是 main thread 357 | - GCD 没有提供 API 直接判断当前队列是否是 main queue 358 | - 派发到 main queue 的任务**必定**在 main thread 上执行 359 | - 执行在 main thread 上的任务**不一定**来自 main queue,也可能来自其他队列 360 | 361 | 参考:[GCD's Main Queue vs. Main Thread](http://blog.benjamin-encz.de/post/main-queue-vs-main-thread/) 362 | 363 | 一个非 main queue 执行在 main thread 上的示例: 364 | ``` C 365 | - (void)test { 366 | dispatch_queue_t queue = dispatch_queue_create("io.iamjiyixuan.queue", DISPATCH_QUEUE_SERIAL); 367 | dispatch_sync(queue, ^{ 368 | NSLog(@"%@", [NSThread currentThread]); // {number = 1, name = main} 369 | NSLog(@"%s", dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)); // io.iamjiyixuan.queue 370 | }); 371 | } 372 | ``` 373 | 374 | ## 17. 如何判断当前队列是否是主队列? 375 | ### 17.1. 方法一:React Native 中的实现,使用 dispatch_queue_set_specific 和 dispatch_get_specific 来设置标志 376 | ``` C 377 | BOOL RCTIsMainQueue() 378 | { 379 | static void *mainQueueKey = &mainQueueKey; 380 | static dispatch_once_t onceToken; 381 | dispatch_once(&onceToken, ^{ 382 | dispatch_queue_set_specific(dispatch_get_main_queue(), 383 | mainQueueKey, mainQueueKey, NULL); 384 | }); 385 | return dispatch_get_specific(mainQueueKey) == mainQueueKey; 386 | } 387 | 388 | // 借助 RCTIsMainQueue 我们很容易实现确保任务在主队列执行的工具函数 389 | void RCTExecuteOnMainQueue(dispatch_block_t block) 390 | { 391 | if (RCTIsMainQueue()) { 392 | block(); 393 | } else { 394 | dispatch_async(dispatch_get_main_queue(), ^{ 395 | block(); 396 | }); 397 | } 398 | } 399 | ``` 400 | 401 | ### 17.2. 方法二:比对当前队列的 label 与主队列的 label 是否一致 402 | ``` C 403 | BOOL XYZIsMainQueue() 404 | { 405 | return strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), 406 | dispatch_queue_get_label(dispatch_get_main_queue())) == 0; 407 | } 408 | ``` 409 | 但这种方法存在一个缺陷,由于 label 不是唯一的,如果我们自己创建一个队列,label 设置成和主队列 label 一样,这样还是会出现误判。因此在实际项目中,我更推荐方法一。 410 | ``` C 411 | - (void)testFakeMainQueue { 412 | dispatch_queue_t queue = dispatch_queue_create(dispatch_queue_get_label(dispatch_get_main_queue()), 413 | DISPATCH_QUEUE_SERIAL); 414 | dispatch_sync(queue, ^{ 415 | XCTAssertFalse(RCTIsMainQueue()); // 测试通过 416 | XCTAssertFalse(XYZIsMainQueue()); // 测试不通过 417 | }); 418 | } 419 | ``` 420 | 421 | ## 18. Dispatch Sources 422 | 423 | ## 19. 参考资料 424 | - [Concurrency Programming Guide](https://developer.apple.com/library/content/documentation/General/Conceptual/ConcurrencyProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008091-CH1-SW1) 425 | - [Threading Programming Guide](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Multithreading/Introduction/Introduction.html#//apple_ref/doc/uid/10000057i) 426 | - [GCD C API](https://developer.apple.com/documentation/dispatch?language=objc) 427 | - [libdispatch 源码](https://github.com/apple/swift-corelibs-libdispatch) 428 | - [《Effective Objective-C 2.0》]() 429 | - #41 多用派发队列,少用同步锁 430 | - #42 多用 GCD,少用 performSelector 系列方法 431 | - #43 掌握 GCD 及操作队列的使用时机 432 | - #44 通过 Dispatch Group 机制,根据系统资源状况来执行任务 433 | - #45 使用 dispatch_once 来执行只需要运行一次的线程安全代码 434 | - #46 不要使用 dispatch_get_current_queue 435 | - [细说 GCD(Grand Central Dispatch)如何用](https://github.com/ming1016/study/wiki/细说GCD(Grand-Central-Dispatch)如何用) by 戴铭 436 | - [GCD 使用经验与技巧浅谈](http://tutuge.me/2015/04/03/something-about-gcd/) by tutuge 2015 437 | - [深入理解 GCD](https://bestswifter.com/deep-gcd/) by bestswifter 2016 438 | - [深入理解 iOS 开发中的锁](https://bestswifter.com/ios-lock/) by bestswifter 2016 439 | - [不再安全的 OSSpinLock](https://blog.ibireme.com/2016/01/16/spinlock_is_unsafe_in_ios/) by ibireme 2016 440 | - [并发编程:API 及挑战](https://objccn.io/issue-2-1/) by objccn 441 | - [常见的后台实践](https://objccn.io/issue-2-2/) by objccn 442 | - [底层并发 API](https://objccn.io/issue-2-3/) by objccn 443 | - [线程安全类的设计](https://objccn.io/issue-2-4/) by objccn 444 | - [测试并发程序](https://objccn.io/issue-2-5) by objccn 445 | - [iOS 知识小集](https://github.com/southpeak/iOS-tech-set) by 南峰子 -------------------------------------------------------------------------------- /HTTP.md: -------------------------------------------------------------------------------- 1 | # iOS 开发中处理 HTTP 2 | 3 | ## 1. 理解 HTTP 协议 4 | 5 | ### 1.1. HTTP/1.1 6 | 7 | ### 1.2. HTTPS 8 | 9 | ### 1.3. HTTP/2 10 | 11 | ### 1.4. WebSocket 12 | 13 | ## 2. 使用 NSURLSession 14 | 15 | ## 3. 使用 AFNetworking 16 | 17 | ## 4. 性能参数 18 | 19 | 响应时间(ms)= DNS 耗时 + TCP 耗时 + SSL 耗时 + 首包耗时 + 网络延迟 20 | 21 | ## 5. Ref 22 | - [移动 APP 网络优化概述](http://blog.cnbang.net/tech/3531/) by bang 2018 23 | - [iOS 客户端 HTTPS 防中间人攻击实践](http://mrpeak.cn/blog/https-mitm/) by mrpeak 2017 24 | - [携程 App 的网络性能优化实践](http://www.infoq.com/cn/articles/how-ctrip-improves-app-networking-performance) 25 | - [京东金融私有云 HTTPS 性能优化实践](http://www.infoq.com/cn/articles/jingdong-financial-private-cloud-https-practices?utm_source=articles_about_architecture-design&utm_medium=link&utm_campaign=architecture-design) 26 | -------------------------------------------------------------------------------- /IM.md: -------------------------------------------------------------------------------- 1 | # 即时通讯 IM 2 | 3 | ## 协议如何选择? 4 | - TCP 5 | - UDP 6 | - HTTP 7 | - HTTP2 8 | - XMPP 9 | - MQTT 10 | - SIP 11 | - WebSocket 12 | 13 | ## IM 云 14 | - [LeanCloud](https://leancloud.cn) 15 | 16 | ## References 17 | - [即时通讯网](http://www.52im.net) - 即时通讯开发者社区 18 | - [新手入门一篇就够:从零开发移动端 IM](http://www.52im.net/thread-464-1-1.html) 19 | - [IM 即时通讯技术在多应用场景下的技术实现,以及性能调优(iOS视角)](https://github.com/ChenYilong/iOSBlog/issues/6) by iOS程序犭袁 -------------------------------------------------------------------------------- /Image.md: -------------------------------------------------------------------------------- 1 | # iOS 图像处理 2 | 3 | ## 1. 相机 4 | 5 | UIImagePickerController 6 | 7 | AVFoundation 8 | 9 | ## 2. 访问相册 10 | 11 | AssetsLibrary 12 | 13 | PhotoKit(since iOS8) 14 | 15 | ## 3. 图片格式 16 | 17 | ## 4. iOS 中用于处理图像的 API 18 | 19 | ### 4.1. UIKit 20 | 21 | ### 4.2. Core Image 22 | 23 | [Core Image Programming Guide](https://developer.apple.com/library/content/documentation/GraphicsImaging/Conceptual/CoreImaging/ci_intro/ci_intro.html) 24 | 25 | ### 4.3. Core Graphics 26 | 27 | ### 4.4. GPUImage 28 | 29 | #### 4.4.1. GPUImage 与 Core Image 的区别 30 | 31 | ### 4.5. OpenGL 32 | 33 | ## 5. References 34 | - [objc.io #21 相机与照片](https://objccn.io/issue-21-0/) -------------------------------------------------------------------------------- /Interview.md: -------------------------------------------------------------------------------- 1 | # 面试 2 | 3 | ## 如何写简历 4 | [如何写面向互联网公司的求职简历](http://blog.devtang.com/2013/12/22/how-to-write-resume-for-it-company/) 5 | 6 | ## References 7 | - [iOSInterviewQuestions](https://github.com/ChenYilong/iOSInterviewQuestions) by ChenYilong 8 | - [iOS-Developer-Interview-Questions](https://github.com/lzyy/iOS-Developer-Interview-Questions) by lzyy 9 | - [怎么面试架构师](https://casatwy.com/zen-yao-mian-shi-jia-gou-shi.html) by casatwy 2015 10 | - [招聘一个靠谱的 iOS](http://blog.sunnyxx.com/2015/07/04/ios-interview/) by sunnyxx 2015 11 | - [BAT 面试指南](https://bestswifter.com/bat-interview/) by bestswifter 2016 12 | - [如何面试 iOS 工程师](http://blog.cnbang.net/internet/3245/) by bang 2016 13 | - [2016 年 10 月求职记:iOS 工作经验不到 1 年,在 1 个月内拿到了 3 个offer](https://knightsj.github.io/2017/01/13/2016年10月求职记:iOS工作经验不到1年,在1个月内拿到了3个offer/) by J_Knight 2017 14 | - [2017 年 5 月 iOS 招人心得(附面试题)](https://knightsj.github.io/2017/06/08/2017年5月iOS招人心得(附面试题)/) by J_Knight 2017 -------------------------------------------------------------------------------- /KVC&KVO.md: -------------------------------------------------------------------------------- 1 | # Key-Value Coding & Observing 2 | 3 | ## 1. KVC 4 | 5 | ### 1.1. API 6 | ``` ObjC 7 | @property (nonatomic, copy) NSString *name; 8 | 9 | // get 10 | NSString *name = [object valueForKey:@"name"]; 11 | 12 | // set 13 | [object setValue:@"Daniel" forKey:@"name"]; 14 | ``` 15 | 16 | ### 1.2. 如何在 Swift 4 中使用 KVC 17 | 18 | ## 2. KVO 19 | 20 | ### 2.1. API 21 | 22 | ### 2.2. 实现原理 23 | 24 | ### 2.3. KVOController 25 | 26 | ## 3. References 27 | - [Key-Value Coding Programming Guide](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/KeyValueCoding/) 28 | - [Key-Value Observing Programming Guide](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html) 29 | - [如何优雅地使用 KVO](https://draveness.me/kvocontroller) by draveness 2017 30 | - [如何自己动手实现 KVO](http://tech.glowing.com/cn/implement-kvo/) by Glow 技术团队博客 2015 31 | - [KVC 和 KVO](https://www.objccn.io/issue-7-3/) by objccn 2014 32 | - [ObjC KVC 简单探索](http://blog.sunnyxx.com/2014/03/09/objc_kvo_secret/) by sunnyxx 2014 -------------------------------------------------------------------------------- /OC_Block.md: -------------------------------------------------------------------------------- 1 | # 深入理解 Objective-C Block 2 | 3 | ## 1. 基本用法 4 | 5 | 定义一个最简单的 block 6 | ``` Objective-C 7 | void (^emptyBlock)(void) = ^{ 8 | NSLog(@"do something ..."); 9 | }; 10 | 11 | emptyBlock(); // print do something ... 12 | ``` 13 | 14 | 定义带参数和返回值的 block 15 | ``` Objective-C 16 | int (^addBlock)(int a, int b) = ^(int a, int b) { 17 | return a + b; 18 | }; 19 | 20 | int result = addBlock(1, 2); // result = 3 21 | ``` 22 | 23 | 作为函数的参数被传递 24 | ``` Objective-C 25 | - (void)testWithBlock:(void (^)(void))block 26 | { 27 | NSLog(@"1 ..."); 28 | block(); 29 | NSLog(@"3 ..."); 30 | } 31 | 32 | [self testWithBlock:^{ 33 | NSLog(@"2 ..."); 34 | }]; 35 | 36 | 执行结果: 37 | 2017-10-03 11:35:12.982009+0800 BlockPlayground[24370:12913141] 1 ... 38 | 2017-10-03 11:35:12.982134+0800 BlockPlayground[24370:12913141] 2 ... 39 | 2017-10-03 11:35:12.982234+0800 BlockPlayground[24370:12913141] 3 ... 40 | ``` 41 | 42 | ## 2. Block 的本质是什么? 43 | - 带有自动变量(局部变量)的匿名函数 44 | - OC 语言对于闭包的实现 45 | - block 实际上也是对象,因为包含 isa 指针 46 | 47 | ## 3. Block 的数据结构设计 48 | 49 | 参考 [libclosure](https://opensource.apple.com/tarballs/libclosure/) 源码 50 | ``` C 51 | struct Block_descriptor_1 { 52 | uintptr_t reserved; 53 | uintptr_t size; 54 | }; 55 | 56 | struct Block_layout { 57 | void *isa; 58 | volatile int32_t flags; // contains ref count 59 | int32_t reserved; 60 | void (*invoke)(void *, ...); 61 | struct Block_descriptor_1 *descriptor; 62 | // imported variables 63 | }; 64 | ``` 65 | 66 | ## 4. Block 的类型 67 | - _NSConcreteGlobalBlock - 全局静态 block,没有用到外界变量或只用到全局变量、静态变量 68 | - _NSConcreteStackBlock - 栈 block 69 | - _NSConcreteMallocBlock - 堆 block 70 | 71 | ## 5. 扩展阅读 72 | - [libclosure 源码](https://opensource.apple.com/tarballs/libclosure/) 73 | - [《Objective-C 高级编程》](https://book.douban.com/subject/24720270/) 第2章 Blocks 74 | - [《Effective Objective-C 2.0》](https://book.douban.com/subject/25829244/) 第6章 块与大中枢派发 75 | - [谈 Objective-C block 的实现](http://blog.devtang.com/2013/07/28/a-look-inside-blocks/) by 唐巧 2013 76 | - [objc 中的 block](https://blog.ibireme.com/2013/11/27/objc-block/) by ibireme 2013 77 | - [Block 类型变量 - 缓存 HTTP 请求与回调](http://tutuge.me/2015/02/19/Block类型变量-缓存Http请求与回调/) by tutuge 2015 78 | - [OC 与 Swift 闭包对比总结](http://www.jianshu.com/p/d0d7b519fec1) by bestswifter 2015 79 | - [对 Strong-Weak Dance 的思考](http://www.jianshu.com/p/4ec18161d790) by bestswifter 2016 80 | - [神奇的 BlocksKit (一)](https://draveness.me/blockskit-1) by draveness 2016 81 | - [神奇的 BlocksKit (二)](https://draveness.me/blockskit-2) by draveness 2016 82 | - [iOS 中的 block 是如何持有对象的](https://draveness.me/block-retain-object) by draveness 2016 83 | - [浅谈 block(1) - clang 改写后的 block 结构](http://www.desgard.com/block1/) by desgard 2016 84 | - [浅谈 block(2) - 截获变量方式](http://www.desgard.com/block2/) by desgard 2016 85 | - [深入研究 Block 捕获外部变量和 __block 实现原理](https://halfrost.com/ios_block/) by halfrost 2016 86 | - [深入研究 Block 用 weakSelf、strongSelf、@weakify、@strongify 解决循环引用](https://halfrost.com/ios_block_retain_circle/) by halfrost 2016 87 | - [如何动态创建 block – JPBlock 扩展原理详解](http://blog.cnbang.net/tech/3332/) by bang 2017 88 | - [iOS weak 关键字漫谈](http://mrpeak.cn/blog/ios-weak/) by mrpeak 2017 89 | - [Weak-Strong-Dance 真的安全吗?](http://www.jianshu.com/p/737999a30544) by kuailejim 2017 -------------------------------------------------------------------------------- /OC_Category.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamjiyixuan/iOS-dev-skill-map/3443673805be5696aa95588e9bb90be586101109/OC_Category.md -------------------------------------------------------------------------------- /OC_Class_Object.md: -------------------------------------------------------------------------------- 1 | # 理解 Objective-C 的类与对象 2 | 3 | ## 1. 定义类 4 | 5 | SimpleClass.h 6 | ``` Objective-C 7 | @interface SimpleClass : NSObject 8 | 9 | // 属性 10 | @property NSString *someProperty; 11 | 12 | // 方法 13 | - (void)someMethod; 14 | 15 | @end 16 | ``` 17 | 18 | SimpleClass.m 19 | ``` Objective-C 20 | #import "SimpleClass.h" 21 | 22 | @implementation SimpleClass 23 | 24 | - (void)someMethod 25 | { 26 | // do something... 27 | } 28 | 29 | @end 30 | ``` 31 | 32 | ## 2. References 33 | - [Programming with Objective-C](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html) -------------------------------------------------------------------------------- /OC_Property.md: -------------------------------------------------------------------------------- 1 | # 理解 Objective-C Property 2 | 3 | @property 是 OC 2.0 新增的一项重要特性,用于封装对象中的数据。 4 | 5 | ## 1. @property 的本质是什么? 6 | 7 | @property = ivar(实例变量)+ getter + setter 8 | 9 | ## 2. 属性特性(property attribute)有哪些? 10 | 11 | - 原子性 12 | - atomic(default) 13 | - nonatomic 14 | 15 | - 内存管理 16 | - assign 17 | - strong - ARC 下使用,语义与 retain 相同 18 | - retain - ARC 下不再使用 19 | - weak 20 | - copy 21 | - unsafe_unretained 22 | 23 | - 读写权限 24 | - readwrite(default) 25 | - readonly 26 | 27 | - 方法名 28 | - getter= 29 | - setter= 30 | 31 | ## 3. ARC 下,属性的默认特性是什么? 32 | 33 | ``` Objective-C 34 | @implementation SomeClass 35 | 36 | // 修饰对象类型 37 | @property (atomic,strong, readwrite) UIView *view; 38 | 39 | // 修饰基本数据类型 40 | @property (atomic,assign, readwrite) int num; 41 | 42 | @end 43 | ``` 44 | 45 | ## 4. atomic 与 nonatomic 的区别? 46 | 47 | 属性默认是 atomic 的,由编译器所合成的 set 方法中会使用同步锁,代码如下: 48 | ``` Objective-C 49 | static inline void 50 | reallySetProperty(id self, SEL _cmd, id newValue, ptrdiff_t offset, bool atomic, bool copy, bool mutableCopy) 51 | { 52 | id oldValue; 53 | id *slot = (id*) ((char*)self + offset); 54 | 55 | if (copy) { 56 | newValue = [newValue copyWithZone:NULL]; 57 | } else if (mutableCopy) { 58 | newValue = [newValue mutableCopyWithZone:NULL]; 59 | } else { 60 | if (*slot == newValue) return; 61 | newValue = objc_retain(newValue); 62 | } 63 | 64 | // 以下代码解释了 atomic 和 nonatomic 的本质区别 65 | if (!atomic) { 66 | oldValue = *slot; 67 | *slot = newValue; 68 | } else { 69 | spin_lock_t *slotlock = &PropertyLocks[GOODHASH(slot)]; 70 | _spin_lock(slotlock); 71 | oldValue = *slot; 72 | *slot = newValue; 73 | _spin_unlock(slotlock); 74 | } 75 | 76 | objc_release(oldValue); 77 | } 78 | ``` 79 | 80 | atomic 会影响性能(有什么数据证明吗?) 81 | 82 | atomic 无法真正保证线程安全,[iOS 多线程到底不安全在哪里?](http://mrpeak.cn/blog/ios-thread-safety/) 83 | 84 | 因此实际开发中一般属性都会声明为 nonatomic 85 | 86 | ## 5. NSString 为什么建议用 copy?如果用 strong 会有什么问题? 87 | 88 | ``` Objective-C 89 | @interface TestProperty : NSObject 90 | 91 | @property(nonatomic, copy) NSString *testCopyString; 92 | @property(nonatomic, strong) NSString *testStrongString; 93 | 94 | @end 95 | ``` 96 | 97 | clang -rewrite-objc 结果 98 | 99 | ``` C 100 | extern "C" unsigned long OBJC_IVAR_$_TestProperty$_testCopyString; 101 | extern "C" unsigned long OBJC_IVAR_$_TestProperty$_testStrongString; 102 | struct TestProperty_IMPL { 103 | struct NSObject_IMPL NSObject_IVARS; 104 | NSString *_testCopyString; 105 | NSString *_testStrongString; 106 | }; 107 | 108 | extern "C" __declspec(dllimport) void objc_setProperty (id, SEL, long, id, bool, bool); 109 | 110 | // get 函数对比 111 | static NSString * 112 | _I_TestProperty_testCopyString(TestProperty * self, SEL _cmd) { 113 | return (*(NSString **)((char *)self + OBJC_IVAR_$_TestProperty$_testCopyString)); 114 | } 115 | 116 | static NSString * 117 | _I_TestProperty_testStrongString(TestProperty * self, SEL _cmd) { 118 | return (*(NSString **)((char *)self + OBJC_IVAR_$_TestProperty$_testStrongString)); 119 | } 120 | 121 | // set 函数对比 122 | static void 123 | _I_TestProperty_setTestCopyString_(TestProperty * self, SEL _cmd, NSString *testCopyString) { 124 | objc_setProperty (self, _cmd, __OFFSETOFIVAR__(struct TestProperty, _testCopyString), (id)testCopyString, 0, 1); 125 | } 126 | 127 | static void 128 | _I_TestProperty_setTestStrongString_(TestProperty * self, SEL _cmd, NSString *testStrongString) { 129 | (*(NSString **)((char *)self + OBJC_IVAR_$_TestProperty$_testStrongString)) = testStrongString; 130 | } 131 | 132 | ``` 133 | 134 | `objc_setProperty()` 执行过程,详见 [objc-accessors.mm](https://opensource.apple.com/source/objc4/objc4-551.1/runtime/Accessors.subproj/objc-accessors.mm.auto.html) 135 | ``` C 136 | void 137 | objc_setProperty(id self, SEL _cmd, ptrdiff_t offset, id newValue, BOOL atomic, signed char shouldCopy) 138 | { 139 | objc_setProperty_non_gc(self, _cmd, offset, newValue, atomic, shouldCopy); 140 | } 141 | 142 | void 143 | objc_setProperty_non_gc(id self, SEL _cmd, ptrdiff_t offset, id newValue, BOOL atomic, signed char shouldCopy) 144 | { 145 | bool copy = (shouldCopy && shouldCopy != MUTABLE_COPY); // #define MUTABLE_COPY 2 146 | bool mutableCopy = (shouldCopy == MUTABLE_COPY); 147 | reallySetProperty(self, _cmd, newValue, offset, atomic, copy, mutableCopy); 148 | } 149 | 150 | static inline void 151 | reallySetProperty(id self, SEL _cmd, id newValue, ptrdiff_t offset, bool atomic, bool copy, bool mutableCopy) 152 | { 153 | id oldValue; 154 | id *slot = (id*) ((char*)self + offset); 155 | 156 | if (copy) { 157 | newValue = [newValue copyWithZone:NULL]; 158 | } else if (mutableCopy) { 159 | newValue = [newValue mutableCopyWithZone:NULL]; 160 | } else { 161 | if (*slot == newValue) return; 162 | newValue = objc_retain(newValue); 163 | } 164 | 165 | // 以下代码解释了 atomic 和 nonatomic 的本质区别 166 | if (!atomic) { 167 | oldValue = *slot; 168 | *slot = newValue; 169 | } else { 170 | spin_lock_t *slotlock = &PropertyLocks[GOODHASH(slot)]; 171 | _spin_lock(slotlock); 172 | oldValue = *slot; 173 | *slot = newValue; 174 | _spin_unlock(slotlock); 175 | } 176 | 177 | objc_release(oldValue); 178 | } 179 | ``` 180 | 181 | 验证 182 | ``` Objective-C 183 | - (void)test 184 | { 185 | TestProperty *obj = [TestProperty new]; 186 | NSString *testString = @"test"; 187 | obj.testCopyString = testString; 188 | obj.testStrongString = testString; 189 | NSLog(@"testString: %p", testString); 190 | NSLog(@".testCopyString: %p", obj.testCopyString); 191 | NSLog(@".testStrongString: %p", obj.testStrongString); 192 | 193 | NSMutableString *testMutableString = [NSMutableString stringWithFormat:@"test"]; 194 | obj.testCopyString = testMutableString; 195 | obj.testStrongString = testMutableString; 196 | NSLog(@"testMutableString: %p", testMutableString); 197 | NSLog(@".testCopyString: %p", obj.testCopyString); 198 | NSLog(@".testStrongString: %p", obj.testStrongString); 199 | } 200 | 201 | 2017-09-04 22:09:37.143 xctest[60519:6403882] testString: 0x11efe30a0 202 | 2017-09-04 22:09:37.144 xctest[60519:6403882] .testCopyString: 0x11efe30a0 203 | 2017-09-04 22:09:37.144 xctest[60519:6403882] .testStrongString: 0x11efe30a0 204 | 205 | 2017-09-04 22:09:37.144 xctest[60519:6403882] testMutableString: 0x7fdab6e1ffb0 206 | 2017-09-04 22:09:37.144 xctest[60519:6403882] .testCopyString: 0xa000000747365744 207 | 2017-09-04 22:09:37.144 xctest[60519:6403882] .testStrongString: 0x7fdab6e1ffb0 208 | ``` 209 | 210 | 总结 211 | - NSString、NSArray、NSDictionary、NSSet 等类都有可变版本子类,为了确保对象本身持有的是一个不可变的副本,需要使用 copy 修饰 212 | 213 | 关于对象 copy 策略 214 | 215 | | - | - | copy | mutableCopy | 216 | | - | - | ---- | ----------- | 217 | | 非集合类对象(NSString)| immutable | 指针复制 / 浅拷贝 | 内容复制 / 深拷贝 | 218 | | 非集合类对象(NSString)| mutable | 内容复制 / 深拷贝 | 内容复制 / 深拷贝 | 219 | | 集合类对象(NSArray、NSDictionary、NSSet)| immutable | 指针复制 / 浅拷贝 | 内容复制 / 深拷贝 | 220 | | 集合类对象(NSArray、NSDictionary、NSSet)| mutable | 内容复制 / 深拷贝 | 内容复制 / 深拷贝 | 221 | 222 | > 集合对象的内容复制仅限于集合对象本身,集合内对象元素仍然是指针复制 223 | 224 | ## 6. @synthesize 与 @dynamic 的作用是什么? 225 | 226 | 如果 `@synthesize` 和 `@dynamic` 都不写,编译器会执行 autosynthesis(自动合成),自动生成 ivar、getter 和 setter。 227 | 228 | `@synthesize` 告诉编译器属性的 ivar 名称。 229 | 230 | ``` Objective-C 231 | @implementation SomeClass 232 | 233 | // 默认写法,含义是:属性 var 的实例变量名叫做 _var 234 | @syntheszie var = _var; 235 | 236 | @end 237 | ``` 238 | > Xcode 4.4 之前必须要写,之后的版本不用,如果不写编译器会自动生成。 239 | 240 | `@dynamic` 告诉编译器属性的 setter 与 getter 方法由用户自己实现,不自动生成。 241 | 242 | ## 7. 参考 243 | - [iOSInterviewQuestions](https://github.com/ChenYilong/iOSInterviewQuestions) 244 | -------------------------------------------------------------------------------- /OC_Runtime.md: -------------------------------------------------------------------------------- 1 | # Objective-C Runtime 2 | 3 | > 本文对应源码版本:[objc4-723](https://opensource.apple.com/tarballs/objc4/objc4-723.tar.gz) 4 | 5 | ## 1. 理解 Objective-C 的动态特性 6 | C 是静态语言,在编译期,函数的调用就会决定调用哪个函数。而 Objective-C 是动态语言,运行时才根据函数名查找对应的函数实现来执行。 7 | 8 | ## 2. Runtime 中涉及的几个重要数据结构 9 | 10 | ### 2.1. NSObject 11 | ``` Objective-C 12 | @interface NSObject { 13 | Class isa OBJC_ISA_AVAILABILITY; 14 | } 15 | ``` 16 | 17 | ### 2.2. Class 18 | ``` C 19 | typedef struct objc_class *Class; 20 | ``` 21 | 22 | ### 2.3. id 23 | ``` C 24 | typedef struct objc_object *id; 25 | ``` 26 | 27 | ### 2.4. objc_class 28 | 这里很好的解释了为什么 Objective-C 中类也是一个对象 29 | ``` C 30 | struct objc_class : objc_object { 31 | Class superclass; 32 | const char *name; 33 | uint32_t version; 34 | uint32_t info; 35 | uint32_t instance_size; 36 | struct old_ivar_list *ivars; 37 | struct old_method_list **methodLists; 38 | Cache cache; 39 | struct old_protocol_list *protocols; 40 | // CLS_EXT only 41 | const uint8_t *ivar_layout; 42 | struct old_class_ext *ext; 43 | 44 | ... 45 | }; 46 | ``` 47 | 48 | ### 2.5. objc_object 49 | ``` C 50 | // objc-private.h 51 | struct objc_object { 52 | private: 53 | isa_t isa; 54 | 55 | ... 56 | }; 57 | ``` 58 | 59 | ### 2.6. isa_t 60 | ``` C 61 | union isa_t 62 | { 63 | isa_t() { } 64 | isa_t(uintptr_t value) : bits(value) { } 65 | 66 | Class cls; 67 | uintptr_t bits; 68 | 69 | ... 70 | }; 71 | ``` 72 | 73 | ## 3. 深入剖析 NSObject 的 alloc 过程 74 | 75 | alloc 76 | ``` Objective-C 77 | + (id)alloc { 78 | return _objc_rootAlloc(self); 79 | } 80 | ``` 81 | 82 | _objc_rootAlloc 83 | ``` C 84 | id 85 | _objc_rootAlloc(Class cls) 86 | { 87 | return callAlloc(cls, false/*checkNil*/, true/*allocWithZone*/); 88 | } 89 | ``` 90 | 91 | callAlloc 92 | ``` C 93 | static ALWAYS_INLINE id 94 | callAlloc(Class cls, bool checkNil, bool allocWithZone=false) 95 | { 96 | if (slowpath(checkNil && !cls)) return nil; 97 | 98 | #if __OBJC2__ 99 | if (fastpath(!cls->ISA()->hasCustomAWZ())) { 100 | // No alloc/allocWithZone implementation. Go straight to the allocator. 101 | // fixme store hasCustomAWZ in the non-meta class and 102 | // add it to canAllocFast's summary 103 | if (fastpath(cls->canAllocFast())) { 104 | // No ctors, raw isa, etc. Go straight to the metal. 105 | bool dtor = cls->hasCxxDtor(); 106 | id obj = (id)calloc(1, cls->bits.fastInstanceSize()); 107 | if (slowpath(!obj)) return callBadAllocHandler(cls); 108 | obj->initInstanceIsa(cls, dtor); 109 | return obj; 110 | } 111 | else { 112 | // Has ctor or raw isa or something. Use the slower path. 113 | id obj = class_createInstance(cls, 0); 114 | if (slowpath(!obj)) return callBadAllocHandler(cls); 115 | return obj; 116 | } 117 | } 118 | #endif 119 | 120 | // No shortcuts available. 121 | if (allocWithZone) return [cls allocWithZone:nil]; 122 | return [cls alloc]; 123 | } 124 | ``` 125 | 126 | initInstanceIsa 127 | ``` C 128 | inline void 129 | objc_object::initInstanceIsa(Class cls, bool hasCxxDtor) 130 | { 131 | assert(!cls->instancesRequireRawIsa()); 132 | assert(hasCxxDtor == cls->hasCxxDtor()); 133 | 134 | initIsa(cls, true, hasCxxDtor); 135 | } 136 | 137 | inline void 138 | objc_object::initIsa(Class cls, bool nonpointer, bool hasCxxDtor) 139 | { 140 | assert(!isTaggedPointer()); 141 | 142 | if (!nonpointer) { 143 | isa.cls = cls; 144 | } else { 145 | assert(!DisableNonpointerIsa); 146 | assert(!cls->instancesRequireRawIsa()); 147 | 148 | isa_t newisa(0); 149 | 150 | #if SUPPORT_INDEXED_ISA 151 | assert(cls->classArrayIndex() > 0); 152 | newisa.bits = ISA_INDEX_MAGIC_VALUE; 153 | // isa.magic is part of ISA_MAGIC_VALUE 154 | // isa.nonpointer is part of ISA_MAGIC_VALUE 155 | newisa.has_cxx_dtor = hasCxxDtor; 156 | newisa.indexcls = (uintptr_t)cls->classArrayIndex(); 157 | #else 158 | newisa.bits = ISA_MAGIC_VALUE; 159 | // isa.magic is part of ISA_MAGIC_VALUE 160 | // isa.nonpointer is part of ISA_MAGIC_VALUE 161 | newisa.has_cxx_dtor = hasCxxDtor; 162 | newisa.shiftcls = (uintptr_t)cls >> 3; 163 | #endif 164 | 165 | // This write must be performed in a single store in some cases 166 | // (for example when realizing a class because other threads 167 | // may simultaneously try to use the class). 168 | // fixme use atomics here to guarantee single-store and to 169 | // guarantee memory order w.r.t. the class index table 170 | // ...but not too atomic because we don't want to hurt instantiation 171 | isa = newisa; 172 | } 173 | } 174 | ``` 175 | 176 | ## 4. 深入理解 +load 方法 177 | 178 | - 钩子方法,在 main 函数执行前被调用 179 | - 重载 +load 方法时不需要 `[super load]`,因为父类的 load 方法会自动被调用,且在子类之前 180 | - 父类先于子类调用,类先于分类调用 181 | - +load 的调用不是惰性的(而 +initialize 是惰性的) 182 | - 如果在类与分类中都实现了 load 方法,它们都会被调用,,不像其它的在分类中实现的方法会被覆盖 183 | - 这个时间点,所有的 framework 都已经加载到了运行时中,所以调用 framework 中的方法都是安全的 184 | - Method Swizzling 一般写在 load 方法中 185 | 186 | ## 5. 深入理解 +initialize 方法 187 | - 钩子方法,惰性调用,+initialize 方法是在类或它的子类收到第一条消息之前被调用的,这里所指的消息包括实例方法和类方法的调用。 188 | - 被调用时,所有的类都已经加载到了内存中 189 | - 线程安全 190 | - 重载 +initialize 方法时不需要 `[super initialize]`,因为子类收到第一条消息时会调用父类的 initialize 191 | 192 | ## 6. References 193 | - [Runtime 源码](https://opensource.apple.com/tarballs/objc4/) 194 | - [Objective-C Runtime Programming Guide](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008048) 195 | - [Objective-C Runtime Reference](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ObjCRuntimeRef/index.html) 196 | - [Objective-C Runtime](http://yulingtianxia.com/blog/2014/11/05/objective-c-runtime/) by 杨萧玉 2014 197 | - [神经病院 Objective-C Runtime 入院第一天—— isa 和 Class](https://halfrost.com/objc_runtime_isa_class/) by halfrost 2016 198 | - [神经病院 Objective-C Runtime 住院第二天——消息发送与转发](https://halfrost.com/objc_runtime_objc_msgsend/) by halfrost 2016 199 | - [神经病院 Objective-C Runtime 出院第三天——如何正确使用 Runtime](https://halfrost.com/how_to_use_runtime/) by halfrost 2016 200 | - [Objc 对象的今生今世](https://halfrost.com/objc_life/) by halfrost 2016 201 | - [重识 Objective-C Runtime - Smalltalk 与 C 的融合](http://blog.sunnyxx.com/2016/08/13/reunderstanding-runtime-0/) by sunnyxx 2016 202 | - [重识 Objective-C Runtime - 看透 Type 与 Value](http://blog.sunnyxx.com/2016/08/13/reunderstanding-runtime-1/) by sunnyxx 2016 203 | - [从 NSObject 的初始化了解 isa](https://draveness.me/isa) by Draveness 2016 204 | - [深入解析 ObjC 中方法的结构](https://draveness.me/method-struct) by Draveness 2016 205 | - [你真的了解 load 方法么?](https://draveness.me/load) by Draveness 2016 206 | - [懒惰的 initialize 方法](https://draveness.me/initialize) by Draveness 2016 207 | - [Objective-C +load vs +initialize](http://blog.leichunfeng.com/blog/2015/05/02/objective-c-plus-load-vs-plus-initialize/) by 雷纯锋 2015 -------------------------------------------------------------------------------- /OpenPlatform.md: -------------------------------------------------------------------------------- 1 | # 开放平台 2 | 3 | ## IM 4 | - [微信开放平台](https://open.weixin.qq.com) 5 | - [钉钉开放平台](https://open.dingtalk.com) 6 | - [LeanCloud](https://leancloud.cn) 7 | - [融云](http://www.rongcloud.cn) 8 | 9 | ## 社交 10 | - [微博开放平台](http://open.weibo.com) 11 | - [Twitter Developers](https://developer.twitter.com) 12 | 13 | ## LBS 14 | - [高德开放平台](http://lbs.amap.com) 15 | - [百度地图开放平台](http://lbsyun.baidu.com) 16 | 17 | ## 协作 18 | - [明道开放平台](https://open.mingdao.com) 19 | - [一起写](https://yiqixie.com) 20 | 21 | ## 支付 22 | - [蚂蚁金服开放平台](https://open.alipay.com/platform/home.htm) 23 | - [Ping++](https://www.pingxx.com) 24 | 25 | ## 电商 26 | - [淘宝开放平台](https://open.taobao.com) 27 | 28 | ## 餐饮 29 | - [饿了么开放平台](https://open.shop.ele.me/openapi) 30 | 31 | ## 医疗健康 32 | - [WeGene 开放平台](https://api.wegene.com) - WeGene 致力于让中国人受益于知道和理解的自己的基因组数据。 现在主要的服务内容包括基于基因组数据的祖源分析、个性化的运动和减肥建议、营养基因组学、基因组医学等方面的内容。未来,我们会跟合作伙伴一起把基因组数据推向每一个被基因所影响的角落。 33 | 34 | ## 监控 35 | - [萤石开放平台](https://open.ys7.com) 36 | 37 | ## 异常上报 38 | - [腾讯 Bugly](https://bugly.qq.com/v2/) -------------------------------------------------------------------------------- /OpenSource.md: -------------------------------------------------------------------------------- 1 | # 开源项目索引 2 | 3 | Index 4 | 5 | 6 | - [UI](#ui) 7 | - [Layout](#layout) 8 | - [UITableView](#uitableview) 9 | - [HUD](#hud) 10 | - [Refresh](#refresh) 11 | - [Keyboard](#keyboard) 12 | - [Animation](#animation) 13 | - [Smooth](#smooth) 14 | - [Chat](#chat) 15 | - [Image](#image) 16 | - [Video](#video) 17 | - [Networking](#networking) 18 | - [HTTP](#http) 19 | - [XMPP](#xmpp) 20 | - [SQLite](#sqlite) 21 | - [Cache](#cache) 22 | - [Model](#model) 23 | - [Util](#util) 24 | - [Log](#log) 25 | - [Hotfix](#hotfix) 26 | - [AOP](#aop) 27 | - [Hook](#hook) 28 | - [Web Front End](#web-front-end) 29 | - [Common](#common) 30 | - [Networking](#networking-1) 31 | - [React](#react) 32 | - [Vue](#vue) 33 | - [Cross Platform](#cross-platform) 34 | - [React Native](#react-native) 35 | - [Weex](#weex) 36 | - [Flutter](#flutter) 37 | - [App](#app) 38 | - [GitHub](#github) 39 | - [IM](#im) 40 | - [Others](#others) 41 | 42 | 43 | 44 | > 语言缩写:OC=Objective-C, JS=JavaScript, TS=TypeScript 45 | > 46 | > Lang=Language, CLOC=Count Lines of Code 47 | 48 | ## UI 49 | 50 | ### Layout 51 | Repo | Stars | Lang | CLOC | 52 | ---- | ----- | ---- | ---- | 53 | [Masonry](https://github.com/SnapKit/Masonry)
Harness the power of AutoLayout NSLayoutConstraints with a simplified, chainable and expressive syntax.

[iOS 源代码分析 ---- Masonry](https://draveness.me/ios-yuan-dai-ma-fen-xi-masonry) by draveness
[读 SnapKit 和 Masonry 自动布局框架源码](http://www.starming.com/2018/04/07/read-snapkit-and-masonry-source-code/) by 戴铭 | ![GitHub stars](https://img.shields.io/github/stars/SnapKit/Masonry.svg?style=social&label=Star) | OC | 25 files, 1.8k lines | 54 | [SnapKit](https://github.com/SnapKit/SnapKit)
Swift 版 Masonry | ![GitHub stars](https://img.shields.io/github/stars/SnapKit/SnapKit.svg?style=social&label=Star) | Swift | 35 files, 1.8k lines | 55 | [Yoga](https://github.com/facebook/yoga)
Yoga is a cross-platform layout engine which implements Flexbox. | ![GitHub stars](https://img.shields.io/github/stars/facebook/yoga.svg?style=social&label=Star) | C++ | 20 files, 5.3k lines | 56 | 57 | ### UITableView 58 | Repo | Stars | Lang | CLOC | 59 | ---- | ----- | ---- | ---- | 60 | [UITableView-FDTemplateLayoutCell](https://github.com/forkingdog/UITableView-FDTemplateLayoutCell)
Template auto layout cell for automatically UITableViewCell height calculating.

[优化 UITableViewCell 高度计算的那些事](http://blog.sunnyxx.com/2015/05/17/cell-height-calculation/) by sunnyxx | ![GitHub stars](https://img.shields.io/github/stars/forkingdog/UITableView-FDTemplateLayoutCell.svg?style=social&label=Star) | OC | 8 files, 517 lines | 61 | 62 | ### HUD 63 | Repo | Stars | Lang | CLOC | 64 | ---- | ----- | ---- | ---- | 65 | [MBProgressHUD](https://github.com/jdg/MBProgressHUD)

[iOS 源代码分析 ---- MBProgressHUD](https://draveness.me/ios-yuan-dai-ma-fen-xi-mbprogresshud) by draveness
[MBProgressHUD 源码解析](http://www.jianshu.com/p/6a5bd5fd8124) by J_Knight
[MBProgressHUD 实现分析](http://southpeak.github.io/2015/03/24/sourcecode-mbprogresshud/) by 南峰子
[结合 Reveal 谈谈 MBProgressHUD 的用法](http://blog.leichunfeng.com/blog/2015/03/16/talking-about-the-usage-of-mbprogresshud-combined-with-reveal/) by 雷纯锋 | [![GitHub stars](https://img.shields.io/github/stars/jdg/MBProgressHUD.svg?style=social&label=Star)](https://github.com/jdg/MBProgressHUD) | OC | 2 files, 1k lines | 66 | [SVProgressHUD](https://github.com/SVProgressHUD/SVProgressHUD)
A clean and lightweight progress HUD for your iOS and tvOS app. | [![GitHub stars](https://img.shields.io/github/stars/SVProgressHUD/SVProgressHUD.svg?style=social&label=Star)](https://github.com/SVProgressHUD/SVProgressHUD) | OC | 8 files, 1.4k lines | 67 | [JGProgressHUD](https://github.com/JonasGessner/JGProgressHUD)
An elegant and simple progress HUD for iOS and tvOS. | [![GitHub stars](https://img.shields.io/github/stars/JonasGessner/JGProgressHUD.svg?style=social&label=Star)](https://github.com/JonasGessner/JGProgressHUD) | OC | 25 files, 1.4k lines | 68 | 69 | ### Refresh 70 | Repo | Stars | Lang | CLOC | 71 | ---- | ----- | ---- | ---- | 72 | [MJRefresh](https://github.com/CoderMJLee/MJRefresh)
An easy way to use pull-to-refresh. | [![GitHub stars](https://img.shields.io/github/stars/CoderMJLee/MJRefresh.svg?style=social&label=Star)](https://github.com/CoderMJLee/MJRefresh) | OC | 39 files, 1.9k lines | 73 | 74 | ### Keyboard 75 | Repo | Stars | Lang | CLOC | 76 | ---- | ----- | ---- | ---- | 77 | [IQKeyboardManager](https://github.com/hackiftekhar/IQKeyboardManager)

[『零行代码』解决键盘遮挡问题(iOS)](https://draveness.me/keyboard) by draveness | [![GitHub stars](https://img.shields.io/github/stars/hackiftekhar/IQKeyboardManager.svg?style=social&label=Star)](https://github.com/hackiftekhar/IQKeyboardManager) | OC | 78 | [TPKeyboardAvoiding](https://github.com/michaeltyson/TPKeyboardAvoiding)
A drop-in universal solution for moving text fields out of the way of the keyboard in iOS. | [![GitHub stars](https://img.shields.io/github/stars/michaeltyson/TPKeyboardAvoiding.svg?style=social&label=Star)](https://github.com/michaeltyson/TPKeyboardAvoiding) | OC | 79 | 80 | ### Animation 81 | Repo | Stars | Lang | 82 | ---- | ----- | -------- | 83 | [pop](https://github.com/facebook/pop)
An extensible iOS and OS X animation library, useful for physics-based interactions. | [![GitHub stars](https://img.shields.io/github/stars/facebook/pop.svg?style=social&label=Star)](https://github.com/facebook/pop) | OC++ | 84 | [lottie-ios](https://github.com/airbnb/lottie-ios)
An iOS library to natively render After Effects vector animations. | [![GitHub stars](https://img.shields.io/github/stars/airbnb/lottie-ios.svg?style=social&label=Star)](https://github.com/airbnb/lottie-ios) | OC | 85 | [Spring](https://github.com/MengTo/Spring)
A library to simplify iOS animations in Swift. | [![GitHub stars](https://img.shields.io/github/stars/MengTo/Spring.svg?style=social&label=Star)](https://github.com/MengTo/Spring) | Swift | 86 | 87 | ### Smooth 88 | Repo | Stars | Lang | CLOC | 89 | ---- | ----- | ---- | ---- | 90 | [AsyncDisplayKit](https://github.com/facebookarchive/AsyncDisplayKit) (ASDK) [已迁移至 [Texture](https://github.com/texturegroup/texture)]
Smooth asynchronous user interfaces for iOS apps.

[iOS 保持界面流畅的技巧](https://blog.ibireme.com/2015/11/12/smooth_user_interfaces_for_ios/) by ibireme
[使用 ASDK 性能调优 - 提升 iOS 界面的渲染性能](https://draveness.me/asdk-rendering) by draveness | ![GitHub stars](https://img.shields.io/github/stars/facebookarchive/AsyncDisplayKit.svg?style=social&label=Star) | OC | 316 fles, 35k lines | 91 | [Texture](https://github.com/texturegroup/texture) | ![GitHub stars](https://img.shields.io/github/stars/texturegroup/texture.svg?style=social&label=Star) | OC | 396 files, 47k lines | 92 | 93 | ### Chat 94 | Repo | Stars | Lang | 95 | ---- | ----- | -------- | 96 | [JSQMessagesViewController](https://github.com/jessesquires/JSQMessagesViewController) [DEPRECATED] | [![GitHub stars](https://img.shields.io/github/stars/jessesquires/JSQMessagesViewController.svg?style=social&label=Star)](https://github.com/jessesquires/JSQMessagesViewController) | OC | 97 | [MessageKit](https://github.com/MessageKit/MessageKit)
In-progress: A community-driven replacement for JSQMessagesViewController. | [![GitHub stars](https://img.shields.io/github/stars/MessageKit/MessageKit.svg?style=social&label=Star)](https://github.com/MessageKit/MessageKit) | Swift | 98 | 99 | ### Image 100 | Repo | Stars | Lang | CLOC | 101 | ---- | ----- | ---- | ---- | 102 | [GPUImage](https://github.com/BradLarson/GPUImage)
An open source iOS framework for GPU-based image and video processing. | [![GitHub stars](https://img.shields.io/github/stars/BradLarson/GPUImage.svg?style=social&label=Star)](https://github.com/BradLarson/GPUImage) | OC | 359 files, 26k lines | 103 | [GPUImage2](https://github.com/BradLarson/GPUImage2)
Swift 版 GPUImage | [![GitHub stars](https://img.shields.io/github/stars/BradLarson/GPUImage2.svg?style=social&label=Star)](https://github.com/BradLarson/GPUImage2) | Swift | 168 files, 6k lines | 104 | [FLAnimatedImage](https://github.com/Flipboard/FLAnimatedImage)
Performant animated GIF engine for iOS. | [![GitHub stars](https://img.shields.io/github/stars/Flipboard/FLAnimatedImage.svg?style=social&label=Star)](https://github.com/Flipboard/FLAnimatedImage) | OC | 105 | [SDWebImage](https://github.com/rs/SDWebImage)
Asynchronous image downloader with cache support as a UIImageView category.

[iOS 源代码分析 ---- SDWebImage](https://draveness.me/ios-yuan-dai-ma-jie-xi-sdwebimage) by draveness | [![GitHub stars](https://img.shields.io/github/stars/rs/SDWebImage.svg?style=social&label=Star)](https://github.com/rs/SDWebImage) | OC | 41 files, 3.1k lines | 106 | [YYImage](https://github.com/ibireme/YYImage)
Image framework for iOS to display/encode/decode animated WebP, APNG, GIF, and more.

[移动端图片格式调研](https://blog.ibireme.com/2015/11/02/mobile_image_benchmark/) by ibireme
[iOS 处理图片的一些小 Tip](https://blog.ibireme.com/2015/11/02/ios_image_tips/) by ibireme | [![GitHub stars](https://img.shields.io/github/stars/ibireme/YYImage.svg?style=social&label=Star)](https://github.com/ibireme/YYImage) | OC | 10 files, 3.4k lines | 107 | [YYWebImage](https://github.com/ibireme/YYWebImage)
Asynchronous image loading framework. | [![GitHub stars](https://img.shields.io/github/stars/ibireme/YYWebImage.svg?style=social&label=Star)](https://github.com/ibireme/YYWebImage) | OC | 37 files, 8.7k lines | 108 | [PINRemoteImage](https://github.com/pinterest/PINRemoteImage)
A thread safe, performant, feature rich image fetcher. | [![GitHub stars](https://img.shields.io/github/stars/pinterest/PINRemoteImage.svg?style=social&label=Star)](https://github.com/pinterest/PINRemoteImage) | OC, Swift | 109 | [ios-twitter-image-pipeline](https://github.com/twitter/ios-twitter-image-pipeline)
Twitter Image Pipeline is a robust and performant image loading and caching framework for iOS clients. | [![GitHub stars](https://img.shields.io/github/stars/twitter/ios-twitter-image-pipeline.svg?style=social&label=Star)](https://github.com/twitter/ios-twitter-image-pipeline) | OC | 110 | [Kingfisher](https://github.com/onevcat/Kingfisher)
A lightweight, pure-Swift library for downloading and caching images from the web. | [![GitHub stars](https://img.shields.io/github/stars/onevcat/Kingfisher.svg?style=social&label=Star)](https://github.com/onevcat/Kingfisher) | Swift | 25 files, 3.8k lines | 111 | [MWPhotoBrowser](https://github.com/mwaterfall/MWPhotoBrowser) [疑似已停更]
A simple iOS photo and video browser with grid view, captions and selections. | [![GitHub stars](https://img.shields.io/github/stars/mwaterfall/MWPhotoBrowser.svg?style=social&label=Star)](https://github.com/mwaterfall/MWPhotoBrowser) | OC | 112 | [TZImagePickerController](https://github.com/banchichen/TZImagePickerController)
一个支持多选、选原图和视频的图片选择器,同时有预览、裁剪功能,支持 iOS6+。| [![GitHub stars](https://img.shields.io/github/stars/banchichen/TZImagePickerController.svg?style=social&label=Star)](https://github.com/banchichen/TZImagePickerController) | OC | 113 | [ZLPhotoBrowser](https://github.com/longitachi/ZLPhotoBrowser)
方便易用的相册多选框架 | [![GitHub stars](https://img.shields.io/github/stars/longitachi/ZLPhotoBrowser.svg?style=social&label=Star)](https://github.com/longitachi/ZLPhotoBrowser) | OC | 114 | 115 | ### Video 116 | Repo | Stars | Lang | 117 | ---- | ----- | -------- | 118 | [ijkplayer](https://github.com/Bilibili/ijkplayer)
Android / iOS video player based on [FFmpeg](http://ffmpeg.org) n3.3, with MediaCodec, VideoToolbox support. | [![GitHub stars](https://img.shields.io/github/stars/Bilibili/ijkplayer.svg?style=social&label=Star)](https://github.com/Bilibili/ijkplayer) | C, OC, Java | 119 | 120 | ## Networking 121 | 122 | ### HTTP 123 | Repo | Stars | Lang | CLOC | 124 | ---- | ----- | ---- | ---- | 125 | [AFNetworking](https://github.com/AFNetworking/AFNetworking)
A delightful networking framework for iOS, macOS, watchOS, and tvOS.

[AFNetworking 概述(一)](https://draveness.me/afnetworking1) by draveness
[AFNetworking 的核心 AFURLSessionManager(二)](https://draveness.me/afnetworking2) by draveness
[处理请求和响应 AFURLSerialization(三)](https://draveness.me/afnetworking3) by draveness
[AFNetworkReachabilityManager 监控网络状态(四)](https://draveness.me/afnetworking4) by draveness
[验证 HTTPS 请求的证书(五)](https://draveness.me/afnetworking5) by draveness
| [![GitHub stars](https://img.shields.io/github/stars/AFNetworking/AFNetworking.svg?style=social&label=Star)](https://github.com/AFNetworking/AFNetworking) | OC | 33 files, 5.1k lines | 126 | [Alamofire](https://github.com/Alamofire/Alamofire)
Swift 版 AFNetworking

[iOS 源代码分析 ---- Alamofire](https://draveness.me/ios-yuan-dai-ma-fen-xi-alamofire) by draveness | [![GitHub stars](https://img.shields.io/github/stars/Alamofire/Alamofire.svg?style=social&label=Star)](https://github.com/Alamofire/Alamofire) | Swift | 18 files, 3.9k lines | 127 | [YTKNetwork](https://github.com/yuantiku/YTKNetwork) | [![GitHub stars](https://img.shields.io/github/stars/yuantiku/YTKNetwork.svg?style=social&label=Star)](https://github.com/yuantiku/YTKNetwork) | OC | 128 | [XMNetworking](https://github.com/kangzubin/XMNetworking) | [![GitHub stars](https://img.shields.io/github/stars/kangzubin/XMNetworking.svg?style=social&label=Star)](https://github.com/kangzubin/XMNetworking) | OC | 129 | [RestKit](https://github.com/RestKit/RestKit)
RestKit is a framework for consuming and modeling RESTful web resources on iOS and OS X. | [![GitHub stars](https://img.shields.io/github/stars/RestKit/RestKit.svg?style=social&label=Star)](https://github.com/RestKit/RestKit) | OC | 130 | 131 | ### XMPP 132 | Repo | Stars | Lang | 133 | ---- | ----- | -------- | 134 | [XMPPFramework](https://github.com/robbiehanson/XMPPFramework) | [![GitHub stars](https://img.shields.io/github/stars/robbiehanson/XMPPFramework.svg?style=social&label=Star)](https://github.com/robbiehanson/XMPPFramework) | OC | 135 | 136 | ## SQLite 137 | Repo | Stars | Lang | CLOC | 138 | ---- | ----- | ---- | ---- | 139 | [SQLite](https://www.sqlite.org/index.html)
SQLite is a self-contained, high-reliability, embedded, full-featured, public-domain, SQL database engine. | | C | 140 | [FMDB](https://github.com/ccgus/fmdb)
A Cocoa / Objective-C wrapper around SQLite. | [![GitHub stars](https://img.shields.io/github/stars/ccgus/fmdb.svg?style=social&label=Star)](https://github.com/ccgus/fmdb) | OC | 19 files, 3.8K lines | 141 | [SQLite.swift](https://github.com/stephencelis/SQLite.swift)
A type-safe, Swift-Lang layer over SQLite3. | [![GitHub stars](https://img.shields.io/github/stars/stephencelis/SQLite.swift.svg?style=social&label=Star)](https://github.com/stephencelis/SQLite.swift) | Swift | 142 | [SQLCipher](https://github.com/sqlcipher/sqlcipher)
SQLCipher is an SQLite extension that provides 256 bit AES encryption of database files. | [![GitHub stars](https://img.shields.io/github/stars/sqlcipher/sqlcipher.svg?style=social&label=Star)](https://github.com/sqlcipher/sqlcipher) | C | 143 | [WCDB](https://github.com/Tencent/wcdb)
WCDB is a cross-platform database framework developed by WeChat.

[微信 WCDB 进化之路 - 开源与开始](https://mp.weixin.qq.com/s/tzy-fr55t1zqTbxOeKg4RA) by WeMobileDev
[微信移动端数据库组件 WCDB 系列(一)iOS 基础篇](https://mp.weixin.qq.com/s?__biz=MzAwNDY1ODY2OQ==&mid=2649286538&idx=1&sn=d11de2d87539a64e991e916013b0f729&chksm=8334c308b4434a1e5670fb68dc087cf34fe91e79bbfc64dbbf092424fd0cd3b28023c67b29ca&scene=21#wechat_redirect) by WeMobileDev
[微信移动端数据库组件 WCDB 系列(二)数据库修复三板斧](https://mp.weixin.qq.com/s?__biz=MzAwNDY1ODY2OQ==&mid=2649286581&idx=1&sn=ab8a10aeb92b424315a10c031b1f7902&chksm=8334c337b4434a219686e08cff86db8efedd4fe7d6ca440b70da4db41b9992ef2871d6b35cc9&scene=21#wechat_redirect) by WeMobileDev
[微信 SQLite 数据库修复实践](https://mp.weixin.qq.com/s?__biz=MzAwNDY1ODY2OQ==&mid=2649286467&idx=1&sn=ea5b6dbfecffd33e333ec814473e1313&chksm=8334c3c1b4434ad7c364ff3acae1e62bc5e871a7350aa9cdcb24bd299b42875f0b020acb3620&scene=21#wechat_redirect) by WeMobileDev
[微信 iOS SQLite 源码优化实践](https://mp.weixin.qq.com/s?__biz=MzAwNDY1ODY2OQ==&mid=2649286361&idx=1&sn=78bbcda7f41a14291ad71289e4821f71&scene=21#wechat_redirect) by WeMobileDev | [![GitHub stars](https://img.shields.io/github/stars/Tencent/wcdb.svg?style=social&label=Star)](https://github.com/Tencent/wcdb) | C, C++ | 144 | [CTPersistance](https://github.com/casatwy/CTPersistance)
Objective-C / Swift Database Persistence Layer with SQLite, your next Persistence Layer! | [![GitHub stars](https://img.shields.io/github/stars/casatwy/CTPersistance.svg?style=social&label=Star)](https://github.com/casatwy/CTPersistance) | OC | 145 | 146 | ## Cache 147 | Repo | Stars | Lang | 148 | ---- | ----- | -------- | 149 | [PINCache](https://github.com/pinterest/PINCache)
Fast, non-deadlocking parallel object cache for iOS, tvOS and OS X. | [![GitHub stars](https://img.shields.io/github/stars/pinterest/PINCache.svg?style=social&label=Star)](https://github.com/pinterest/PINCache) | OC | 150 | [YYCache](https://github.com/ibireme/YYCache)
High performance cache framework for iOS.

[YYCache 设计思路](https://blog.ibireme.com/2015/10/26/yycache/) by ibireme | [![GitHub stars](https://img.shields.io/github/stars/ibireme/YYCache.svg?style=social&label=Star)](https://github.com/ibireme/YYCache) | OC | 151 | 152 | ## Model 153 | Repo | Stars | Lang | CLOC | 154 | ---- | ----- | ---- | ---- | 155 | [Mantle](https://github.com/Mantle/Mantle)
Model framework for Cocoa and Cocoa Touch. | [![GitHub stars](https://img.shields.io/github/stars/Mantle/Mantle.svg?style=social&label=Star)](https://github.com/Mantle/Mantle) | OC | 156 | [MJExtension](https://github.com/CoderMJLee/MJExtension)
A fast, convenient and nonintrusive conversion between JSON and model. | [![GitHub stars](https://img.shields.io/github/stars/CoderMJLee/MJExtension.svg?style=social&label=Star)](https://github.com/CoderMJLee/MJExtension) | OC | 21 files, 1.5K lines | 157 | [YYModel](https://github.com/ibireme/YYModel)
High performance model framework for iOS/OSX. | [![GitHub stars](https://img.shields.io/github/stars/ibireme/YYModel.svg?style=social&label=Star)](https://github.com/ibireme/YYModel) | OC | 5 files, 2K lines | 158 | [SwiftyJSON](https://github.com/SwiftyJSON/SwiftyJSON)
The better way to deal with JSON data in Swift. | [![GitHub stars](https://img.shields.io/github/stars/SwiftyJSON/SwiftyJSON.svg?style=social&label=Star)](https://github.com/SwiftyJSON/SwiftyJSON) | Swift | 159 | 160 | ## Util 161 | Repo | Stars | Lang | CLOC | 162 | ---- | ----- | ---- | ---- | 163 | [dyld](https://github.com/opensource-apple/dyld)
动态链接器

[iOS 程序 main 函数之前发生了什么](http://blog.sunnyxx.com/2014/08/30/objc-pre-main/) by sunnyxx | ![GitHub stars](https://img.shields.io/github/stars/opensource-apple/dyld.svg?style=social&label=Star) | C | 39 files, 16K lines | 164 | [libffi](https://github.com/libffi/libffi)
A portable foreign-function interface library. | ![GitHub stars](https://img.shields.io/github/stars/libffi/libffi.svg?style=social&label=Star) | C | 124 files, 28k lines | 165 | [RxSwift](https://github.com/ReactiveX/RxSwift) | [![GitHub stars](https://img.shields.io/github/stars/ReactiveX/RxSwift.svg?style=social&label=Star)](https://github.com/ReactiveX/RxSwift) | Swift | 166 | [BlocksKit](https://github.com/BlocksKit/BlocksKit)

[神奇的 BlocksKit (一)](https://draveness.me/blockskit-1) by draveness
[神奇的 BlocksKit (二)](https://draveness.me/blockskit-2) by draveness | [![GitHub stars](https://img.shields.io/github/stars/BlocksKit/BlocksKit.svg?style=social&label=Star)](https://github.com/BlocksKit/BlocksKit) | OC | 167 | [KVOController](https://github.com/facebook/KVOController)
Simple, modern, thread-safe key-value observing for iOS and OS X.

[如何优雅地使用 KVO](https://draveness.me/kvocontroller) by draveness 2017 | ![GitHub stars](https://img.shields.io/github/stars/facebook/KVOController.svg?style=social&label=Star) | OC | 5 files, 554 lines | 168 | [MLeaksFinder](https://github.com/Tencent/MLeaksFinder) | [![GitHub stars](https://img.shields.io/github/stars/Tencent/MLeaksFinder.svg?style=social&label=Star)](https://github.com/Tencent/MLeaksFinder) | OC | 169 | 170 | ## Log 171 | Repo | Stars | Lang | CLOC | 172 | ---- | ----- | ---- | ---- | 173 | [CocoaLumberjack](https://github.com/CocoaLumberjack/CocoaLumberjack)
A fast & simple, yet powerful & flexible logging framework for Mac and iOS. | [![GitHub stars](https://img.shields.io/github/stars/CocoaLumberjack/CocoaLumberjack.svg?style=social&label=Star)](https://github.com/CocoaLumberjack/CocoaLumberjack) | OC | 174 | 175 | ## Hotfix 176 | Repo | Stars | Lang | 177 | ---- | ----- | -------- | 178 | [JSPatch](https://github.com/bang590/JSPatch)
JSPatch bridge Objective-C and Javascript using the Objective-C runtime.

[JSPatch – 动态更新iOS APP](http://blog.cnbang.net/works/2767/) by bang
[JSPatch 实现原理详解](http://blog.cnbang.net/tech/2808/) by bang
[JSPatch 实现原理详解<二>](http://blog.cnbang.net/tech/2855/) by bang
[JSPatch 部署安全策略](http://blog.cnbang.net/tech/2879/) by bang
[JSPatch Convertor 实现原理详解](http://blog.cnbang.net/tech/2915/) by bang
[回应一下 JSPatch 安全问题](http://blog.cnbang.net/internet/2990/) by bang
[JSPatch 平台介绍](http://blog.cnbang.net/archives/) by bang
[JSPatch 近期新特性解析](http://blog.cnbang.net/tech/3038/) by bang
[JSPatch 更新:完善开发功能模块的能力](http://blog.cnbang.net/tech/3123/) by bang
[如何动态调用 C 函数](http://blog.cnbang.net/tech/3219/) by bang
[iOS 动态更新方案对比:JSPatch vs React Native](http://blog.cnbang.net/archives/) by bang
[如何动态创建 block - JPBlock 扩展原理详解](http://blog.cnbang.net/tech/3332/) by bang
| [![GitHub stars](https://img.shields.io/github/stars/bang590/JSPatch.svg?style=social&label=Star)](https://github.com/bang590/JSPatch) | C, OC | 179 | 180 | ## AOP 181 | Repo | Stars | Lang | CLOC | 182 | ---- | ----- | ---- | ---- | 183 | [Aspects](https://github.com/steipete/Aspects)
Delightful, simple library for aspect oriented programming.

[iOS 如何实现 Aspect Oriented Programming](https://halfrost.com/ios_aspect/) by halfrost | ![GitHub stars](https://img.shields.io/github/stars/steipete/Aspects.svg?style=social&label=Star) | OC | 2 files, 777 lines | 184 | 185 | ## Hook 186 | Repo | Stars | Lang | CLOC | 187 | ---- | ----- | ---- | ---- | 188 | [fishhook](https://github.com/facebook/fishhook)
A library that enables dynamically rebinding symbols in Mach-O binaries running on iOS.

[动态修改 C 语言函数的实现](https://draveness.me/fishhook) by draveness
[巧用符号表 - 探求 fishhook 原理(一)](http://www.desgard.com/fishhook-1/) by desgard
[验证试验 - 探求 fishhook 原理(二)](http://www.desgard.com/fishhook-2/) by desgard | ![GitHub stars](https://img.shields.io/github/stars/facebook/fishhook.svg?style=social&label=Star) | C | 2 files, 196 lines | 189 | [BlockHook](https://github.com/yulingtianxia/BlockHook)
Hook Objective-C blocks with libffi.

[Hook Objective-C Block with Libffi](http://yulingtianxia.com/blog/2018/02/28/Hook-Objective-C-Block-with-Libffi/) by 杨萧玉 | ![GitHub stars](https://img.shields.io/github/stars/yulingtianxia/BlockHook.svg?style=social&label=Star) | OC | 2 files, 381 lines | 190 | 191 | ## Web Front End 192 | 193 | ### Common 194 | Repo | Stars | Lang | CLOC | 195 | ---- | ----- | ---- | ---- | 196 | [pinyin](https://github.com/hotoo/pinyin)
转换中文字符为拼音。可以用于汉字注音、排序、检索。支持多音字、繁体、多种不同拼音风格。 | [![GitHub stars](https://img.shields.io/github/stars/hotoo/pinyin.svg?style=social&label=Star)](https://github.com/hotoo/pinyin) | JS | 197 | [Redux](https://github.com/reactjs/redux)
Predictable state container for JavaScript apps. | 35,000+ | JS | 198 | 199 | ### Networking 200 | Repo | Stars | Lang | CLOC | 201 | ---- | ----- | ---- | ---- | 202 | [axios](https://github.com/axios/axios)
Promise based HTTP client for the browser and node.js. | [![GitHub stars](https://img.shields.io/github/stars/axios/axios.svg?style=social&label=Star)](https://github.com/axios/axios) | JS | 107 files, 6.8k lines | 203 | [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch)
Isomorphic WHATWG Fetch API, for Node & Browserify. | [![GitHub stars](https://img.shields.io/github/stars/matthew-andrews/isomorphic-fetch.svg?style=social&label=Star)](https://github.com/matthew-andrews/isomorphic-fetch) | JS | 8 files, 150 lines | 204 | 205 | ### React 206 | Repo | Stars | Lang | CLOC | 207 | ---- | ----- | ---- | ---- | 208 | [React](https://github.com/facebook/react)
A declarative, efficient, and flexible JavaScript library for building user interfaces. | [![GitHub stars](https://img.shields.io/github/stars/facebook/react.svg?style=social&label=Star)](https://github.com/facebook/react) | JS | 698 files, 120K lines | 209 | [React Redux](https://github.com/reactjs/react-redux)
Official React bindings for Redux. | 9,800+ | JS | 210 | [redux-saga](https://github.com/redux-saga/redux-saga)
一个用于管理 Redux 应用异步操作的中间件。 | 9,800+ | JS | 211 | [React Router](https://github.com/ReactTraining/react-router)
Declarative routing for React. | 25,000+ | JS | 212 | [react-router-redux](https://github.com/reactjs/react-router-redux)
Ruthlessly simple bindings to keep react-router and redux in sync. | 6,700+ | JS | 213 | [dva](https://github.com/dvajs/dva)
支付宝前端团队出品的基于 redux、redux-saga 和 react-router 的轻量级前端框架。 | 6,300+ | JS | 214 | 215 | ### Vue 216 | Repo | Stars | Lang | CLOC | 217 | ---- | ----- | ---- | ---- | 218 | [Vue.js](https://github.com/vuejs/vue)
A progressive, incrementally-adoptable JavaScript framework for building UI on the web. | [![GitHub stars](https://img.shields.io/github/stars/vuejs/vue.svg?style=social&label=Star)](https://github.com/vuejs/vue) | JS | 219 | 220 | ## Cross Platform 221 | 222 | ### React Native 223 | Repo | Stars | Lang | CLOC | 224 | ---- | ----- | ---- | ---- | 225 | [React Native](https://github.com/facebook/react-native)
A framework for building native apps with React.

[React Native 源码导读(零) – 创建/运行/调试](http://blog.cnbang.net/tech/3461/) by bang
[React Native 通信机制详解](http://blog.cnbang.net/tech/2698/) by bang | 57,000+ | JS, OC, Java | 226 | [react-navigation](https://github.com/react-community/react-navigation)
Learn once, navigate anywhere. RN 官方导航解决方案。 | 7,700+ | JS | | 227 | [react-native-navigation](https://github.com/wix/react-native-navigation)
A complete native navigation solution for React Native. | 5,000+ | JS, OC, Java | | 228 | [native-navigation](https://github.com/airbnb/native-navigation)
Native navigation library for React Native applications. airbnb 出品的 RN 导航解决方案。 | 2,500+ | JS | | 229 | [react-native-calendars](https://github.com/wix/react-native-calendars)
React Native Calendar Components. | 1,400+ | JS | | 230 | [react-native-sqlite-storage](https://github.com/andpor/react-native-sqlite-storage)
Full featured SQLite3 Native Plugin for React Native (Android and iOS). | 1,000+ | JS, Java, OC | | 231 | [ant-design-mobile](https://github.com/ant-design/ant-design-mobile)
antd-mobile 是 Ant Design 的移动规范的 React 实现,服务于蚂蚁及口碑无线业务。 | 3,200+ | TS | | 232 | 233 | ### Weex 234 | Repo | Stars | Lang | CLOC | 235 | ---- | ----- | ---- | ---- | 236 | [Weex](https://github.com/apache/incubator-weex)
A framework for building Mobile cross-platform UI.

[Weex Conf 2018](http://weex-project.io/weexConf2018/)
[Weex + Ui - Weex Conf 2018](https://zhuanlan.zhihu.com/p/33153760?iam=08abed520609736c2d292670aeb38a28?utm_medium=social&utm_source=weibo) by 汤威(侑夕),飞猪高级前端工程师
[Weex Conf 2018 参会小结:Weex 的现状和未来](https://juejin.im/post/5a620abf6fb9a01c9950e4a0) by 没故事的卓同学 | [![GitHub stars](https://img.shields.io/github/stars/apache/incubator-weex.svg?style=social&label=Star)](https://github.com/apache/incubator-weex) | JS, OC, Java | 237 | [weex-ui](https://github.com/alibaba/weex-ui)
A rich interaction, lightweight, high performance UI library based on Weex. | [![GitHub stars](https://img.shields.io/github/stars/alibaba/weex-ui.svg?style=social&label=Star)](https://github.com/alibaba/weex-ui) | JS | 238 | 239 | ### Flutter 240 | Repo | Stars | Lang | 241 | ---- | ----- | -------- | 242 | [flutter](https://github.com/flutter/flutter)
Flutter makes it easy and fast to build beautiful mobile apps. | ![GitHub stars](https://img.shields.io/github/stars/flutter/flutter.svg?style=social&label=Star) | Dart | 243 | 244 | ## App 245 | 246 | ### GitHub 247 | Repo | Stars | Lang | CLOC | 248 | ---- | ----- | ---- | ---- | 249 | [GitHub Desktop](https://github.com/desktop/desktop)
GitHub Desktop is an open source Electron-based GitHub app. It is written in TypeScript and uses React. | ![GitHub stars](https://img.shields.io/github/stars/desktop/desktop.svg?style=social&label=Star) | TS | 730 files, 62k lines | 250 | 251 | ### IM 252 | Repo | Stars | Lang | CLOC | 253 | ---- | ----- | ---- | ---- | 254 | [Telegram](https://github.com/peter-iakovlev/Telegram)
Telegram Messenger for iOS | ![GitHub stars](https://img.shields.io/github/stars/peter-iakovlev/Telegram.svg?style=social&label=Star) | OC | | 255 | [Messenger](https://github.com/relatedcode/Messenger)
This is a native iOS Messenger app, with audio/video calls and realtime chat conversations (full offline support). | ![GitHub stars](https://img.shields.io/github/stars/relatedcode/Messenger.svg?style=social&label=Star) | OC | | 256 | 257 | ### Others 258 | Repo | Stars | Lang | CLOC | 259 | ---- | ----- | ---- | ---- | 260 | [DanTang](https://github.com/hrscy/DanTang)
Swift - 单糖 | ![GitHub stars](https://img.shields.io/github/stars/hrscy/DanTang.svg?style=social&label=Star) | Swift | | 261 | [SwiftLanguageWeather](https://github.com/JakeLin/SwiftLanguageWeather)
Swift Language Weather is an iOS weather app developed in Swift 4. | ![GitHub stars](https://img.shields.io/github/stars/JakeLin/SwiftLanguageWeather.svg?style=social&label=Star) | Swift | | 262 | 263 | 264 | 265 | 266 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # iOS 开发知识库 2 | 3 | - 编程语言 4 | - [C](C.md) 5 | - C++ 6 | - Objective-C 7 | - [基础] Class & Object 8 | - [基础] [Property](OC_Property.md) 9 | - [基础] Method 10 | - [基础] Protocol 11 | - [基础] [Category](OC_Category.md) 12 | - [基础] [Block](OC_Block.md) 13 | - [基础] 错误处理 14 | - [进阶] [Runtime](OC_Runtime.md) 15 | - [进阶] 内存管理 16 | - [高阶] Clang Attributes 17 | - [高阶] dyld 18 | - [高阶] Mach-O 19 | - [Swift](Swift.md) 20 | - [ES6](ES6.md) 21 | - Ruby 22 | - 汇编语言 23 | - 编程范式 24 | - 面向对象编程 25 | - 泛型编程 26 | - 函数式编程 27 | - 响应式编程 28 | - 数据结构与算法 29 | - 排序 30 | - 数组 31 | - 链表 32 | - 队列 33 | - 栈 34 | - [二叉树](Algorithm/BinaryTree.md) 35 | - 红黑树 36 | - B 树 37 | - 哈希 38 | - 压缩 39 | - Foundation 40 | - NSString 41 | - Time 42 | - 集合 43 | - NSArray 44 | - NSSet 45 | - NSDictionary 46 | - Notification 47 | - [KVC 和 KVO](KVC&KVO.md) 48 | - [GNUstep](http://gnustep.org) - 开源版 Cocoa(Cocoa 在 NeXT 时代叫 OpenStep) 49 | - UI 50 | - UIApplication 51 | - UIWindow 52 | - UIView 53 | - UIViewController 54 | - 布局 55 | - Frame 56 | - AutoLayout 57 | - FlexBox 58 | - [响应链](ResponderChain.md) 59 | - 手势 60 | - 导航 61 | - UITableView 62 | - UICollectionView 63 | - iOS New Features 64 | - iPhone X 65 | - iOS 11 66 | - iOS 10 67 | - iOS 9 68 | - iOS 8 69 | - iOS 7 70 | - 网络 71 | - 协议 72 | - TCP 73 | - HTTP 74 | - DNS 75 | - XMPP 76 | - API 77 | - NSURLConnection Deprecated in iOS 9 78 | - NSURLSession 79 | - 存储 80 | - Sandbox 81 | - keychain 82 | - SQLite 83 | - 并发 84 | - [GCD](GCD.md) 85 | - Operation Queue 86 | - [Runloop](Runloop.md) 87 | - Lock 88 | - 多媒体 89 | - Image 90 | - Audio 91 | - Video 92 | - LBS 93 | - 架构 94 | - MVC 95 | - MVVM 96 | - VIPER 97 | - 设计模式 98 | - 工程 99 | - 版本控制 100 | - svn 101 | - git 102 | - 依赖管理 103 | - CocoaPods 104 | - Carthage 105 | - Testing 106 | - CI 107 | - Hot Fix 108 | - 安全 109 | - 逆向工程 110 | - [开源项目](OpenSource.md) 111 | - [开放平台](OpenPlatform.md) 112 | - 应用领域 113 | - 即时通信 114 | - 人工智能 115 | - [区块链](Blockchain.md) 116 | - 了解技术团队中的其他角色 117 | - 产品设计 118 | - 视觉设计 119 | - 服务器开发 120 | - 运维 121 | - 运营 -------------------------------------------------------------------------------- /README[DEPRECATED].md: -------------------------------------------------------------------------------- 1 | # iOS 开发技能图谱 2 | 3 | 目录 4 | 5 | 6 | - [编程语言](#编程语言) 7 | - [Cocoa 基础](#cocoa-基础) 8 | - [UI](#ui) 9 | - [APNS](#apns) 10 | - [iOS 新特性](#ios-新特性) 11 | - [网络](#网络) 12 | - [存储](#存储) 13 | - [并发](#并发) 14 | - [多媒体](#多媒体) 15 | - [LBS](#lbs) 16 | - [机器学习](#机器学习) 17 | - [架构](#架构) 18 | - [Hybrid / JS-Native](#hybrid--js-native) 19 | - [软件工程](#软件工程) 20 | - [逆向工程](#逆向工程) 21 | - [算法与数据结构](#算法与数据结构) 22 | - [安全](#安全) 23 | - [操作系统](#操作系统) 24 | - [硬件设备](#硬件设备) 25 | - [职业生涯](#职业生涯) 26 | - [辅助工具](#辅助工具) 27 | - [开源项目](#开源项目) 28 | - [开放平台](#开放平台) 29 | 30 | 31 | 32 | ## 编程语言 33 | - [C](编程语言/C/README.md) 34 | - 标准库(libc) 35 | - 指针 36 | - 内存管理 37 | - [Objective-C](编程语言/Objective-C/README.md) 38 | - OC 方面的好书不多,推荐 [《Effective Objective-C 2.0》](https://book.douban.com/subject/25829244/) 和 [《Objective-C 高级编程》](https://book.douban.com/subject/24720270/) 这两本,但不适合初学者,建议有一定基础后再阅读。 39 | - 了解 OC 语言的起源 40 | - 基础 41 | - 类与对象 42 | - NSObject 43 | - [属性 @property](编程语言/Objective-C/oc_property.md) 44 | - 方法 45 | - 协议 46 | - Category 47 | - Block 48 | - 循环引用 49 | - weak-strong dance 50 | - 为什么需要 `__weak typeof(self) weakSelf = self;`?答:避免循环引用。 51 | - 为什么需要 `__strong typeof(self) strongSelf = weakSelf;`?答:防止 block 执行到一半的时候 self 被释放。里需要注意,持有 self 的行为是在 block 执行的时候才发生,因此有可能在 block 执行前 self 已经被释放,更安全的做法应该是在 block 内部使用 strongSelf 时仍然需要 nil 检测防止 Crash。 52 | - 进阶 53 | - Runtime 54 | - 对象模型 55 | - 关联对象(Associated Objects) 56 | - 消息转发机制 57 | - Method Swizzling 58 | - 内存管理 59 | - 引用计数 60 | - ARC 61 | - @autoreleasepool 62 | - 高阶 63 | - Clang Attributes 64 | - [dyld](编程语言/Objective-C/dyld.md) 65 | - [C++](编程语言/C++/README.md) 66 | - [Swift](Swift.md) 67 | - [JavaScript / ES6](编程语言/ES6/README.md) 68 | - 汇编语言 69 | 70 | ## Cocoa 基础 71 | - NSString 72 | - NSNumber 73 | - 集合 74 | - NSArray 75 | - NSSet 76 | - NSDictionary 77 | - NSPredicate 78 | - Notification 79 | - KVO 80 | - [GNUstep](http://gnustep.org) - 开源版 Cocoa(Cocoa 在 NeXT 时代叫 OpenStep) 81 | 82 | ## UI 83 | - 布局 84 | - frame 85 | - Auto Layout 86 | - Cassowary 算法 87 | - VFL 88 | - Masonry 89 | - 控件 90 | - UIView 91 | - UIButton 92 | - UITableview 93 | - UICollectionView 94 | - 转场 95 | - 手势 96 | - 动画 97 | - Storyboard 98 | - 保持界面流畅 99 | - 3rd 100 | - [AsyncDisplayKit](https://github.com/facebookarchive/AsyncDisplayKit) 已更名并迁移至 [Texture](https://github.com/texturegroup/texture/) 101 | - 扩展阅读 102 | - [iOS 保持界面流畅的技巧](http://blog.ibireme.com/2015/11/12/smooth_user_interfaces_for_ios/) by ibireme 2015.11 103 | 104 | ## APNS 105 | - [国内 90%以上的 iOS 开发者,对 APNs 的认识都是错的](http://www.jianshu.com/p/ace1b422bad4) by iOS程序犭袁 2016.04 106 | 107 | ## iOS 新特性 108 | - iPhone X 109 | - Safe Area 110 | - Face ID 111 | - [苹果官方 iPhone X 适配指南](https://developer.apple.com/cn/ios/update-apps-for-iphone-x/) 112 | - iOS 11 113 | - Core ML 114 | - ARKit 115 | - 扩展阅读 116 | - [WWDC 2017](https://developer.apple.com/videos/wwdc2017/) 117 | - [开发者所需要知道的 iOS 11 SDK 新特性](https://onevcat.com/2017/06/ios-11-sdk/) by onevcat 2017.06 118 | - iOS 10 119 | - Extension 120 | - SiriKit 121 | - 扩展阅读 122 | - [WWDC 2016](https://developer.apple.com/videos/wwdc2016/) 123 | - [开发者所需要知道的 iOS 10 SDK 新特性](https://onevcat.com/2016/06/ios-10-sdk/) by onevcat 2016.06 124 | - iOS 9 125 | - Multitasking 126 | - UI Test 127 | - 扩展阅读 128 | - [WWDC 2015](https://developer.apple.com/videos/wwdc2015/) 129 | - [开发者所需要知道的 iOS 9 SDK 新特性](https://onevcat.com/2015/06/ios9-sdk/) by onevcat 2015.06 130 | - iOS 8 131 | - [iOS 8 VoIP Notifications](http://pierremarcairoldi.com/ios-8-voip-notifications/) by Pierre-Marc Airoldi 2015.03 132 | - 扩展阅读 133 | - [WWDC 2014](https://developer.apple.com/videos/wwdc2014/) 134 | - [开发者所需要知道的 iOS 8 SDK 新特性](https://onevcat.com/2014/07/developer-should-know-about-ios8/) by onevcat 2014.07 135 | - iOS 7 136 | - Multitasking 137 | - [WWDC 2013 Session 204 - What's New with Multitasking](https://developer.apple.com/videos/play/wwdc2013/204/) 138 | - 后台获取 (Background Fetch) 139 | - 推送唤醒 / 静默推送 (Silent Remote Notifications) 140 | - 后台传输 (Background Transfer Service) 141 | - 扩展阅读 142 | - [WWDC 2013](https://developer.apple.com/videos/wwdc2013/) 143 | - [开发者所需要知道的 iOS 7 SDK 新特性](https://onevcat.com/2013/06/developer-should-know-about-ios7/) by onevcat 2013.06 144 | 145 | ## 网络 146 | - TCP/IP 147 | - TCP 属于 Transport 层协议 148 | - TCP 头格式 149 | - TCP 的状态机 150 | - TCP 重传机制 151 | - 抓包 152 | - tcpdump 153 | - [iOS, Android 网络抓包教程之 tcpdump](http://mrpeak.cn/blog/tutorial-tcpdump/) by MrPeak 2016.02 154 | - Wireshark 155 | - [Wireshark 抓包 iOS 入门教程](http://mrpeak.cn/blog/wireshark/) by MrPeak 2016.11 156 | - 扩展阅读 157 | - [TCP 的那些事儿(上)](http://coolshell.cn/articles/11564.html) by 陈皓 2014.05 158 | - [TCP 的那些事儿(下)](http://coolshell.cn/articles/11609.html) by 陈皓 2014.05 159 | - MrPeak 的 TCP/IP 系列 160 | - [TCP/IP 系列之初印象](http://mrpeak.cn/blog/tcp-preface/) by MrPeak 2017.03 161 | - [TCP/IP 系列之 Header 篇](http://mrpeak.cn/blog/tcp-headers/) by MrPeak 2017.03 162 | - [TCP/IP 系列之重新认识 IP 地址](http://mrpeak.cn/blog/tcp-ip/) by MrPeak 2017.03 163 | - [TCP/IP 系列之 TCP 流控与拥塞控制(一)](http://mrpeak.cn/blog/tcp-flow-control00/) by MrPeak 2017.04 164 | - [TCP/IP 系列之包与流](http://mrpeak.cn/blog/tcp-packet-stream/) by MrPeak 2017.05 165 | - Socket API 166 | - TCP 服务端: socket() -> bind() -> listen() -> accept() ... close() 167 | - TCP 客户端: socket() -> connect() ... close() 168 | - struct addrinfo 169 | - getaddrinfo() & freeaddrinfo() - 域名解析 170 | - socket(domain, type, protocol) 171 | - domain - 协议域,又称为协议族(family) 172 | - type - socket 类型 173 | - protocol - 指定协议 174 | - connect() 175 | - 1)向服务器发送 SYN J 包 176 | - 2)进入阻塞状态 177 | - 3)收到服务器的 SYN K ,ACK J+1 之后返回 178 | - bind() 179 | - listen() 180 | - accept() 181 | - I/O 182 | - read() & write() 183 | - recv() & send() 184 | - close() 185 | - HTTP 186 | - HTTPS 187 | - HTTP2 188 | - DNS 189 | 190 | ## 存储 191 | - 沙盒机制 192 | - Bundle 193 | - 钥匙串 194 | - SQLite 195 | - 缓存 196 | - 数据格式 197 | - xml 198 | - json 199 | 200 | ## 并发 201 | - [Concurrency Programming Guide](https://developer.apple.com/library/content/documentation/General/Conceptual/ConcurrencyProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008091) 202 | - [Threading Programming Guide](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Multithreading/AboutThreads/AboutThreads.html) 203 | - 进程 204 | - 线程 205 | - [GCD](GCD.md) 206 | - [libdispatch 源码](https://opensource.apple.com/tarballs/libdispatch/) 207 | - OperationQueue 208 | - [NSOperation](https://developer.apple.com/reference/foundation/nsoperation?language=objc) 209 | - 适合用于封装可重复、耗时的任务。相较基于 block 的 GCD,NSOperation 的最大优点是可控。 210 | - 子类:NSInvocationOperation, NSBlockOperation 211 | - 状态机: ready → executing → finished 212 | - KVO 属性 213 | - isCancelled 214 | - isAsynchronous 215 | - isExecuting 216 | - isFinished 217 | - isReady 218 | - dependencies 219 | - queuePriority 220 | - completionBlock 221 | - 自定义 Operation 覆盖方法 222 | - 对于 non-concurrent 操作 223 | - main 224 | - 默认行为:不执行任何操作 225 | - 不要调用 `super` 226 | - 自动在 NSOperation 提供的 autorelease pool 中执行 227 | - 对于 concurrent 操作 228 | - start 229 | - 默认行为:1)更新执行状态;2)调用 `main`;3)如果当前操作处于不合适的状态,则抛 NSInvalidArgumentException 异常 230 | - 不要调用 `super` 231 | - 自己管理状态机 232 | - manually generate KVO notifications for the isExecuting and isFinished key paths 233 | - asynchronous 234 | - executing 235 | - finished 236 | - [NSOperationQueue](https://developer.apple.com/reference/foundation/nsoperationqueue?language=objc) 237 | - 扩展阅读 238 | - [WWDC 2015 Session 226 - Advanced NSOperations](https://developer.apple.com/videos/play/wwdc2015/226/) | 示例代码: [Advanced-NSOperations.zip](https://developer.apple.com/sample-code/wwdc/2015/downloads/Advanced-NSOperations.zip) 239 | - [Advanced NSOperation 源代码分析(一)](https://chengwey.com/advanced-nsoperation-yuan-dai-ma-fen-xi/) by chengway 2015.07 240 | - [NSOperation](http://nshipster.com/nsoperation/) by Mattt Thompson 2014.07 241 | - [iOS 并发编程之 Operation Queues](http://blog.leichunfeng.com/blog/2015/07/29/ios-concurrency-programming-operation-queues/) by 雷纯锋 2015.07 242 | - 锁 243 | - [深入理解 iOS 开发中的锁](https://bestswifter.com/ios-lock/) by bestswifter 2016.10 244 | - Runloop 245 | - [NSRunLoop](https://developer.apple.com/documentation/foundation/nsrunloop) - 246 | - [CFRunLoopRef](https://developer.apple.com/documentation/corefoundation/cfrunloop-rht) - 属于 CoreFoundation 框架,提供 C API,且所有 API 都线程安全。CFRunLoopRef 是开源的,源码地址: [http://opensource.apple.com/tarballs/CF/](http://opensource.apple.com/tarballs/CF/) 247 | - 扩展阅读 248 | - [深入理解 RunLoop](http://blog.ibireme.com/2015/05/18/runloop/) by ibireme 2015.05 249 | - [深入研究 Runloop 与线程保活](https://bestswifter.com/runloop-and-thread/) by bestswifter 2016.07 250 | 251 | ## 多媒体 252 | - 图片 253 | - 音频 254 | - [Audio Session Programming Guide](https://developer.apple.com/library/content/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007875) 255 | - iOS 音频播放 by 程寅 2014 256 | - [iOS音频播放 (一):概述](http://msching.github.io/blog/2014/07/07/audio-in-ios/) 257 | - [iOS音频播放 (二):AudioSession](http://msching.github.io/blog/2014/07/08/audio-in-ios-2/) 258 | - [iOS音频播放 (三):AudioFileStream](http://msching.github.io/blog/2014/07/09/audio-in-ios-3/) 259 | - [iOS音频播放 (四):AudioFile](http://msching.github.io/blog/2014/07/19/audio-in-ios-4/) 260 | - [iOS音频播放 (五):AudioQueue](http://msching.github.io/blog/2014/08/02/audio-in-ios-5/) 261 | - [iOS音频播放 (六):简单的音频播放器实现](http://msching.github.io/blog/2014/08/09/audio-in-ios-6/) 262 | - [iOS音频播放 (七):播放iPod Library中的歌曲](http://msching.github.io/blog/2014/09/07/audio-in-ios-7/) 263 | - [iOS音频播放 (八):NowPlayingCenter和RemoteControl](http://msching.github.io/blog/2014/11/06/audio-in-ios-8/) 264 | - [iOS音频播放 (九):边播边缓存](http://msching.github.io/blog/2016/05/24/audio-in-ios-9/) 265 | - 视频 266 | 267 | ## LBS 268 | 269 | ## 机器学习 270 | - [Apple Machine Learning](https://developer.apple.com/machine-learning/) 271 | - [Core ML](https://developer.apple.com/documentation/coreml) 272 | - [WWDC 2017 Session 703 - Introducing Core ML](https://developer.apple.com/videos/play/wwdc2017/703/) 273 | - [WWDC 2017 Session 710 - Core ML in depth](https://developer.apple.com/videos/play/wwdc2017/710/) 274 | - [Vision](https://developer.apple.com/documentation/vision) 275 | - Natural Language Processing 276 | - [WWDC 2017 Session 208 - Natural Language Processing and your Apps](https://developer.apple.com/videos/play/wwdc2017/208/) 277 | 278 | ## 架构 279 | - 面向对象编程(Object-Oriented Programming) 280 | - 面向切面编程(Aspect-Oriented Programming) 281 | - Aspects 282 | - 面向协议编程(Protocol-Oriented Programming) 283 | - 函数式编程(Functional Programming) 284 | - 响应式编程(Reactive Programming) 285 | - [ReactiveX](http://reactivex.io) 286 | - [RxSwift](https://github.com/ReactiveX/RxSwift) 287 | - [ReactiveCocoa](https://github.com/ReactiveCocoa/ReactiveCocoa) 288 | - MVC 289 | - MVVM 290 | - 设计模式 291 | - 单例 292 | - 工厂 293 | - 观察者 294 | - 组件化 295 | - 扩展阅读 296 | - [iOS 应用架构谈 组件化方案](https://casatwy.com/iOS-Modulization.html) by Casa Taloyum 2016.03 297 | - Model 298 | - 3rd 299 | - [remodel](https://github.com/facebook/remodel) 300 | - 扩展阅读 301 | - [Improving Immutable Object Initialization in Objective-C](http://holko.pl/2015/05/12/immutable-object-initialization/) by Arek Holko 2015.05 302 | - [去 model 化和数据对象](https://casatwy.com/OOP_nomodel.html) by Casa Taloyum 2016.05 303 | - [iOS 创建对象的姿势](http://mrpeak.cn/blog/ios-init/) by MrPeak 2017.01 304 | - [Facebook model 库 Remodel 观感](http://mrpeak.cn/blog/remodel/) by MrPeak 2017.05 305 | - 响应式架构 306 | - 扩展阅读 307 | - [iOS 响应式架构](http://blog.mrriddler.com/2017/06/28/iOS响应式架构/) by mrriddler 2017.06 308 | 309 | ## Hybrid / JS-Native 310 | - 对 WEB 前端技术的发展和开发模式应该有基本的认识 311 | - [Roadmap to becoming a web developer in 2017](https://github.com/kamranahmedse/developer-roadmap) 312 | - [front-end-guide](https://github.com/grab/front-end-guide) - Study guide and introduction to the modern front end stack. 313 | - HTML 314 | - 1995 年,JavaScript(简称 JS)诞生。 315 | - [mozilla 官方的 JavaScript 技术文档](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript) 316 | - JS 的标准化进程 317 | - 1996 年,标准化为 ECMAScript(简称 ES),JS 成为 ES 的一种实现,另外的 ES 方言还有 Jscript 和 ActionScript。 318 | - 2009 年,ES5 标准发布。 319 | - 2015 年,ES6 / ES2015 标准发布,新增了许多 [新特性](https://babeljs.io/learn-es2015/)。推荐阅读 [阮一峰的 《ECMAScript 6 入门》](http://es6.ruanyifeng.com)。 320 | - [js-stack-from-scratch](https://github.com/verekia/js-stack-from-scratch) 教你从零开始构建 JavaScript 技术栈。 321 | - 2012 年 10 月,微软发布 [TypeScript](http://www.typescriptlang.org),一种自由和开源的编程语言,JavaScript 的严格超集。设计目标是开发大型应用,然后转译成 JavaScript。 322 | - 1996 年,CSS 诞生 323 | - [Flexbox](https://www.w3.org/TR/css-flexbox-1/) 324 | - Ajax 325 | - XMLHttpRequest 326 | - 2009 年,JavaScript 运行环境 [Node.js](https://nodejs.org/en/) 发布。[NPM](https://www.npmjs.com) 是 Node 默认的包管理器,随 Node 自动安装。另一个流行的 JS 包管理器是 2016 年发布的 [Yarn](https://yarnpkg.com/)。 327 | - 2010 年,MVC 框架 [Backbone.js](http://backbonejs.org) 和 MVVM 框架 [Angular.js](https://angular.io) 发布 328 | - 2012 年,自动化工具 [Grunt](https://gruntjs.com) 发布 329 | - 2012 年,打包工具 [webpack](https://webpack.github.io) 发布 330 | - 核心概念 331 | - Entry - 入口,告诉 webpack 从哪里开始 332 | - Output - 出口,告诉 webpack bundle 的名称,以及我们想要生成到哪里 333 | - Loader 334 | - Plugins 335 | - 2013 年,Facebook 发布 [React.js](https://facebook.github.io/react/),是一套全新的开发模式 336 | - 核心技术 Virtual DOM 337 | - 采用 JSX 语法描述界面,需要通过 [Babel](https://babeljs.io) 翻译为标准 JS 代码才能运行在浏览器或 Node 上 338 | - 组件 339 | - 状态管理 340 | - [Flux](http://facebook.github.io/flux/) 架构 341 | - [MobX](https://mobx.js.org) 架构 342 | - [Redux](http://redux.js.org) 架构 343 | - 路由 344 | - [React Router](https://github.com/ReactTraining/react-router) 345 | - 3rd 346 | - [awesome-react](https://github.com/enaqx/awesome-react) 347 | - [React-Bootstrap](https://react-bootstrap.github.io) 348 | - [Element React](https://github.com/eleme/element-react) 349 | - 2014 年,MVVM 框架 [Vue.js](https://vuejs.org) 发布。2016 年,Vue 2.0 发布。 350 | - 与 React 一样,也基于 Virtual DOM 技术(但实现上有差异)。 351 | - 采用模板语法(合法的 HTML)描述界面,相比 JXS 更接近 Web 标准。 352 | - 组件化开发:Vue.js 设计了一个 `*.vue` 格式的文件,令每一个组件的样式、模板和脚本集合成了一整个文件,每个文件就是一个组件,同时还包含了组件之间的依赖关系。 353 | - 组件 354 | - 状态管理 355 | - [vuex](https://vuex.vuejs.org/zh-cn/) 356 | - 路由 357 | - [vue-router](http://router.vuejs.org/zh-cn/) 358 | - 3rd 359 | - [awesome-vue](https://github.com/vuejs/awesome-vue) 360 | - [element](https://github.com/ElemeFE/element) - 饿了么前端团队出品的基于 Vue 2.0 的组件库。 361 | - [iview](https://github.com/iview/iview) 362 | - [vux](https://github.com/airyland/vux) - Vue UI Components based on [WeUI](https://github.com/weui/weui) 363 | - 基于 JS-Native 的跨平台方案 364 | - 2015 年,Facebook 发布基于 React 的移动端开发框架 [React Native](http://facebook.github.io/react-native/),宣称 `Learn once, write anywhere`。 365 | - React 概念 366 | - JSX 367 | - components - 组件 368 | - state - 状态,可变的 369 | - props - 属性,固定不变的 370 | - Style - 每个 component 都有一个名为 `style` 的 prop 371 | - 外观 372 | - 布局 373 | - flexbox 374 | - [React Native Styling Cheat Sheet](https://github.com/vhpoet/react-native-styling-cheat-sheet) - Most of the React Native styling material in one page. 375 | - 基础组件 376 | - React Native 与 Native 间通信 377 | - iOS 378 | - Native → React Native 379 | - 方式一:通过 `RCTRootView` 的 `initWithBridge:moduleName:initialProperties:` 初始化方法传入属性。通过设置 `RCTRootView` 的 read-only 属性 `appProperties` 来更新。设置新属性后(新值与旧值不同时),React Native 将重新渲染界面。 380 | - React Native → Native 381 | - Native Modules 382 | - RCTBridgeModule 383 | - RCT_EXPORT_MODULE() - 注册供 js 调用的模块 384 | - RCT_EXPORT_METHOD() or RCT_REMAP_METHOD() - 注册供 js 调用的方法 385 | - Android 386 | - for Web 387 | - [React Native for Web](https://github.com/necolas/react-native-web) - Twitter 工程师 Nicolas Gallagher 开发,使 React Native 组件可以在 Web 端工作。React Native for Web 与 React Native for iOS and Android 是平级关系。 388 | - [react-web](https://github.com/taobaofed/react-web) - 淘宝出品 A framework for building web apps with React Native compatible API. 389 | - 2017 年 4 月,微软发布基于 React Native 的跨平台开发框架 [ReactXP](https://microsoft.github.io/reactxp/),支持 Web。 390 | - 3rd 391 | - [awesome-react-native](https://github.com/jondot/awesome-react-native) 392 | - 组件库 393 | - [React-Native-Elements](https://github.com/react-native-community/React-Native-Elements) - Cross Platform React Native UI Toolkit. 394 | - [NativeBase](https://github.com/GeekyAnts/NativeBase) - Essential cross-platform UI components for React Native. 395 | - [Shoutem UI](https://github.com/shoutem/ui) - Customizable set of components for React Native applications. 396 | - [lottie-react-native](https://github.com/airbnb/lottie-react-native) - Lottie component for React Native (iOS and Android). Lottie is a mobile library for Android and iOS that parses Adobe After Effects animations exported as JSON with bodymovin and renders them natively on mobile! 397 | - [30-days-of-react-native](https://github.com/fangwei716/30-days-of-react-native) - 30 days of React Native examples (inspired by 30DaysofSwift). 398 | - [react-native-hiapp](https://github.com/BelinChung/react-native-hiapp) - A simple and Twitter like demo app written in react-native. 399 | - [react-native-nw-react-calculator](https://github.com/benoitvallon/react-native-nw-react-calculator) - Mobile, desktop and website Apps with the same code. 工程结构值得借鉴。 400 | - 扩展阅读 401 | - [React Native 在 Glow 的实践](http://tech.glowing.com/cn/react-native-at-glow/) by Allen 许帅 2017.04 402 | - [React Native 通信机制详解](http://blog.cnbang.net/tech/2698/) by bang 2015.03 403 | - [Moles:携程基于 React Native 的跨平台开发框架](http://www.infoq.com/cn/articles/ctrip-moles) by 魏晓军 2016.07 404 | - 2017 年,阿里发布跨平台用户界面开发框架 [Weex](https://weex.apache.org),宣称 `一次编写,多端运行`,目前支持 iOS、Android、HTML5 三端,并支持 Vue 语法。可以把 Weex 看成 Vue Native。 405 | - [WEEX Conf](https://yq.aliyun.com/activity/145) 406 | - [中文 FAQ](https://segmentfault.com/t/weex) 407 | - 扩展阅读 408 | - [Weex 是如何在 iOS 客户端上跑起来的](https://www.halfrost.com/weex_ios/) by 一缕殇流化隐半边冰霜 2017.03 409 | - [由 FlexBox 算法强力驱动的 Weex 布局引擎](https://www.halfrost.com/weex_flexbox/) by 一缕殇流化隐半边冰霜 2017.04 410 | - [Weex 事件传递的那些事儿](https://www.halfrost.com/weex_event/) by 一缕殇流化隐半边冰霜 2017.04 411 | - [Weex 中别具匠心的 JS Framework](https://www.halfrost.com/weex_js_framework/) by 一缕殇流化隐半边冰霜 2017.04 412 | - [iOS 开发者的 Weex 伪最佳实践指北](https://www.halfrost.com/weex_best_practice_guidelines/) by 一缕殇流化隐半边冰霜 2017.05 413 | 414 | ## 软件工程 415 | - 脚本 416 | - Shell 417 | - Ruby 418 | - Python 419 | - Perl 420 | - Node.js 421 | - 包管理 422 | - CocoaPods 423 | - Carthage 424 | - 代码管理 425 | - svn 426 | - git 427 | - [廖雪峰的 Git 教程](http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000) 428 | - 理解 `集中式` 与 `分布式` 的区别 429 | - 基本操作 430 | - git init 431 | - git add 432 | - git commit 433 | - git status 434 | - git diff 435 | - git log - 查看提交历史 436 | - git reflog - 查看命令历史 437 | - git reset 438 | - 分支管理 439 | - 搭建 git 服务器 440 | - 测试 441 | - 单元测试 442 | - 自动化 UI 测试 443 | - 性能监控 / APM 444 | - 测量效率 445 | - [NSDate date] 446 | - clock() 447 | - CFAbsoluteTimeGetCurrent() 448 | - CACurrentMediaTime() 449 | - mach_absolute_time() 450 | - dispatch_benchmark 451 | - 卡顿检测 452 | - 网络监控 453 | - 扩展阅读 454 | - [移动端监控体系之技术原理剖析](http://www.jianshu.com/p/8123fc17fe0e) by Joy___ 2017.02 455 | - [微信读书 iOS 质量保证及性能监控](http://wereadteam.github.io/2016/12/12/Monitor/) by 微信读书技术团队 2016.12 456 | - [网易 NeteaseAPM iOS SDK 技术实现分享](http://www.infoq.com/cn/articles/netease-ios-sdk-neteaseapm-technology-share) by 朱志强 2016.05 457 | - [Benchmarking](http://nshipster.cn/benchmarking/) by Mattt Thompson 撰写 Croath Liu 翻译 2014.05 458 | - 3rd lib 459 | - [GodEye](https://github.com/zixun/GodEye) - Automaticly display Log, Crash, Network, ANR, Leak, CPU, RAM, FPS, NetFlow, Folder and etc with one line of code based on Swift. Just like God opened his eyes. 460 | - 持续集成 461 | - xcodebuild 462 | - xctool 463 | - 发布 464 | - 热修复 465 | - JSPatch - 目前已经被苹果禁止使用了 466 | - 异常处理 467 | - 设备日志 468 | - 深入理解 Crash 469 | - [如何定位Obj-C野指针随机Crash(一):先提高野指针Crash率](http://dev.qq.com/topic/59141e56ca95d00d727ba750) by 腾讯 Bugly 470 | - [如何定位Obj-C野指针随机Crash(二):让非必现Crash变成必现](http://dev.qq.com/topic/59142d61ca95d00d727ba752) by 腾讯 Bugly 471 | - [如何定位Obj-C野指针随机Crash(三):如何让Crash自报家门](http://dev.qq.com/topic/5915134b75d11c055ca7fca0) by 腾讯 Bugly 472 | - [iOS 崩溃 crash 大解析](http://www.qidiandasheng.com/2016/04/10/crash-xuebeng/) by 齐滇大圣 2016.04 473 | - Hook 技术 474 | - 第三方服务 475 | - 运营统计 476 | - 任务管理 477 | - 文档 478 | 479 | ## 逆向工程 480 | - 越狱 481 | 482 | ## 算法与数据结构 483 | 484 | ## 安全 485 | 486 | ## 操作系统 487 | - Unix 488 | - BSD 489 | - Darwin 490 | - 内核:XNU 491 | - 可执行文件:Mach-O 492 | 493 | ## 硬件设备 494 | - iPhone 495 | - 4 / 4S 496 | - 5 / 5C / 5S 497 | - 6 / 6 Plus / 6S / 6S Plus 498 | - SE 499 | - 7 / 7 Plus 500 | - iPad 501 | - 1, 2, 3, 4 502 | - Air 1, 2 503 | - Mini 1, 2, 3, 4 504 | - Pro 505 | 506 | ## 职业生涯 507 | - 面试 & 招聘 508 | - [iOSInterviewQuestions](https://github.com/ChenYilong/iOSInterviewQuestions) by ChenYilong 509 | - [iOS-Developer-Interview-Questions](https://github.com/lzyy/iOS-Developer-Interview-Questions) by lzyy 510 | - [怎么面试架构师](https://casatwy.com/zen-yao-mian-shi-jia-gou-shi.html) 511 | - [招聘一个靠谱的 iOS](http://blog.sunnyxx.com/2015/07/04/ios-interview/) by sunnyxx 2015.07 512 | - [BAT 面试指南](https://bestswifter.com/bat-interview/) by bestswifter 2016.04 513 | - [如何面试 iOS 工程师](http://blog.cnbang.net/internet/3245/) by bang 2016.09 514 | - [2016 年 10 月求职记:iOS 工作经验不到 1 年,在 1 个月内拿到了 3 个offer](https://knightsj.github.io/2017/01/13/2016年10月求职记:iOS工作经验不到1年,在1个月内拿到了3个offer/) by J_Knight 2017.01 515 | - [2017 年 5 月 iOS 招人心得(附面试题)](https://knightsj.github.io/2017/06/08/2017年5月iOS招人心得(附面试题)/) by J_Knight 2017.06 516 | - 技术人员发展之路 & 工程师文化 517 | - [这多年来我一直在钻研的技术](http://coolshell.cn/articles/17446.html) by 陈皓 2016.08 518 | - [什么是工程师文化?](http://coolshell.cn/articles/17497.html) by 陈皓 2016.09 519 | - [技术人员的发展之路](http://coolshell.cn/articles/17583.html) by 陈皓 2016.12 520 | - 如何面对绩效 521 | - [我看绩效考核](http://coolshell.cn/articles/17972.html) by 陈皓 2017.07 522 | - 创业 523 | - [写在创业五周年](http://blog.devtang.com/2017/05/31/startup-5th-year-summary/) by 唐巧 2017.05 524 | 525 | ## 辅助工具 526 | - 终端 / Shell 527 | - [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) 528 | - [iTerm2](https://github.com/gnachman/iTerm2) 529 | - CLI 530 | - [Homebrew](https://brew.sh) - macOS 下必备,用于安装其他 CLI 工具。 531 | - tree - 以树状格式打印文件目录结构。Linux 下自带,macOS 下需要用 `brew install tree` 安装。 532 | - 更多终端工具 -> [terminals-are-sexy](https://github.com/k4m4/terminals-are-sexy) 533 | - [Visual Studio Code](https://code.visualstudio.com) 534 | - [StarUML](http://staruml.io) 535 | - [SourceTree](https://www.sourcetreeapp.com) - Git 客户端 536 | - 应用推荐社区 537 | - [少数派](https://sspai.com) 538 | - [利器](http://liqi.io) 539 | 540 | ## 开源项目 541 | - [传送门](OpenSource.md) 542 | 543 | ## 开放平台 544 | - [传送门](OpenPlatform.md) -------------------------------------------------------------------------------- /React.md: -------------------------------------------------------------------------------- 1 | # React 2 | 3 | ## 1. toolchain 4 | - [Visual Studio Code](https://code.visualstudio.com) 5 | - [Node.js](https://nodejs.org/en/) + [nvm](https://github.com/creationix/nvm) 6 | - [npm](https://www.npmjs.com) / [yarn](https://yarnpkg.com/zh-Hans/) 7 | - private npm repo server 8 | - [sinopia](https://github.com/rlidwka/sinopia) 9 | - [verdaccio](https://github.com/verdaccio/verdaccio) - a fork of sinopia 10 | - 脚手架工具 11 | - React 官方出品: [create-react-app](https://github.com/facebookincubator/create-react-app) 12 | - 蚂蚁金服出品: [dva-cli](https://github.com/dvajs/dva-cli) baseed on [roadhog](https://github.com/sorrycc/roadhog) 13 | - [Babel](https://babeljs.io) 14 | - [webpack](https://webpack.js.org) 15 | - [ESLint](https://eslint.org) 16 | - [Prettier](https://prettier.io) - Code Formatter 17 | - [Electron](https://electronjs.org) 18 | - Test 19 | - [Jest](http://facebook.github.io/jest/) 20 | - [enzyme](http://airbnb.io/enzyme/) 21 | - HTTP 22 | - 标准 Fetch 23 | - 兼容版 Fetch: [github-fetch](https://github.com/github/fetch) / [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch) 24 | - 基于 [XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) 的 [axios](https://github.com/axios/axios) 25 | 26 | ## 2. 搭建舒适的开发环境 27 | 28 | ### 2.1. Node.js 29 | 30 | ### 2.2. yarn 替代 npm 31 | 32 | ### 2.3. 用 VS Code 编写代码 33 | 34 | ### 2.4. 用 Babel 35 | 36 | ## 3. 使用 Jest 编写单元测试 37 | 38 | ### 3.1. 测试异步函数 39 | - Callback API 40 | - Promise API 41 | - Async/Await 42 | 43 | ### 3.2. Mock 44 | 45 | ## 4. References 46 | 47 | ### 4.1. React Native 48 | - [RN 官网](http://facebook.github.io/react-native/) 49 | - [React Native 通信机制详解](http://blog.cnbang.net/tech/2698/) by bang 2015 50 | - [React Native 源码导读(零) – 创建/运行/调试](http://blog.cnbang.net/tech/3461/) by bang 2017 51 | - [ReactNative 源码解析 —— 通信机制详解(1/2)](http://zxfcumtcs.github.io/2017/10/08/ReactNativeCommunicationMechanism/) by 赵雪峰 2017 52 | - [ReactNative 源码解析 —— 通信机制详解(2/2)](http://zxfcumtcs.github.io/2017/10/12/ReactNativeCommunicationMechanism2/) by 赵雪峰 2017 53 | - [ReactNative 源码解析 —— 通信机制详解(补充条款)](http://zxfcumtcs.github.io/2017/11/22/RNCommunicationMechanism-AdditionalTerms/) by 赵雪峰 2017 54 | - [React Native 在 Glow 的实践](http://tech.glowing.com/cn/react-native-at-glow/) by Glow 技术团队 2017 55 | - [如何实现 React Native 里的页面导航系统](http://tech.glowing.com/cn/all-about-routing-and-navigation-in-react-native/) by Glow 技术团队 2018 56 | 57 | ### 4.2. Electron 58 | - [How to build an Electron app using create-react-app. No webpack configuration or “ejecting” necessary.](https://medium.freecodecamp.org/building-an-electron-application-with-create-react-app-97945861647c) by Christian Sepulveda -------------------------------------------------------------------------------- /ResponderChain.md: -------------------------------------------------------------------------------- 1 | # Responder Chain 2 | 3 | ## 1. 事件(UIEvent) 4 | 5 | - Touch events 6 | - Press events 7 | - Shake-motion events 8 | - Remote-control events 9 | - Editing menu messages 10 | 11 | ## 2. 响应者(UIResponder) 12 | 13 | iOS 应用程序中只有响应者(UIResponder 的实例)可以接收和处理事件。UIApplication、UIView、UIViewController 这几个 UIKit 的核心类都是直接继承自 UIResponder。响应者接收到事件后,可以选择自己处理或者传递给下一个响应者(nextResponder)。第一个接收到事件的响应者称为第一响应者(first responder),谁是第一响应者由事件类型决定。事件沿着响应链被传递,直到被处理。 14 | 15 | ## 3. 事件通过响应链被传递 16 | 17 | 方向:子视图 → 父视图 → UIWindow → UIApplication → UIApplicationDelegate 18 | 19 | ![Responder chains in an app](https://docs-assets.developer.apple.com/published/7c21d852b9/f17df5bc-d80b-4e17-81cf-4277b1e0f6e4.png) 20 | 21 | ## 4. Hit-Testing 22 | 23 | ## 5. References 24 | - [Understanding Event Handling, Responders, and the Responder Chain](https://developer.apple.com/documentation/uikit/touches_presses_and_gestures/understanding_event_handling_responders_and_the_responder_chain?language=objc) -------------------------------------------------------------------------------- /Reverse.md: -------------------------------------------------------------------------------- 1 | # iOS 逆向工程 2 | 3 | 目录 4 | 5 | 6 | - [1. 越狱](#1-越狱) 7 | - [2. 砸壳](#2-砸壳) 8 | - [2.1. 下载安装 dumpdecrypted](#21-下载安装-dumpdecrypted) 9 | - [2.2. 连接越狱设备](#22-连接越狱设备) 10 | - [2.3. 找到可执行文件的位置](#23-找到可执行文件的位置) 11 | - [2.4. 执行砸壳](#24-执行砸壳) 12 | - [3. class-dump](#3-class-dump) 13 | - [4. 参考资料](#4-参考资料) 14 | 15 | 16 | 17 | ## 1. 越狱 18 | 19 | ## 2. 砸壳 20 | 我们直接从 AppStore 上面下载安装的应用都被苹果进行了加密,无法直接进行逆向。因此需要先破坏这一层保护壳,这就是所谓的“砸壳”。 21 | 22 | ### 2.1. 下载安装 dumpdecrypted 23 | ``` 24 | $ mkdir reverse_workspace 25 | 26 | $ cd reverse_workspace 27 | 28 | $ git clone git://github.com/stefanesser/dumpdecrypted/ 29 | Cloning into 'dumpdecrypted'... 30 | remote: Counting objects: 31, done. 31 | remote: Total 31 (delta 0), reused 0 (delta 0), pack-reused 31 32 | Receiving objects: 100% (31/31), 7.10 KiB | 0 bytes/s, done. 33 | Resolving deltas: 100% (15/15), done. 34 | 35 | $ cd dumpdecrypted 36 | $ make 37 | xcrun --sdk iphoneos --find gcc` -Os -Wimplicit -isysroot `xcrun --sdk iphoneos --show-sdk-path` -F`xcrun --sdk iphoneos --show-sdk-path`/System/Library/Frameworks -F`xcrun --sdk iphoneos --show-sdk-path`/System/Library/PrivateFrameworks -arch armv7 -arch armv7s -arch arm64 -c -o dumpdecrypted.o dumpdecrypted.c 38 | 2017-03-30 10:25:53.841 xcodebuild[14645:344677] [MT] PluginLoading: Required plug-in compatibility UUID DFFB3951-EB0A-4C09-9DAC-5F2D28CC839C for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/ClangFormat.xcplugin' not present in DVTPlugInCompatibilityUUIDs 39 | `xcrun --sdk iphoneos --find gcc` -Os -Wimplicit -isysroot `xcrun --sdk iphoneos --show-sdk-path` -F`xcrun --sdk iphoneos --show-sdk-path`/System/Library/Frameworks -F`xcrun --sdk iphoneos --show-sdk-path`/System/Library/PrivateFrameworks -arch armv7 -arch armv7s -arch arm64 -dynamiclib -o dumpdecrypted.dylib dumpdecrypted.o 40 | ``` 41 | 42 | make 完成后的目录结构: 43 | ``` 44 | dumpdecrypted 45 | ├── Makefile 46 | ├── README 47 | ├── dumpdecrypted.c 48 | ├── dumpdecrypted.dylib 49 | └── dumpdecrypted.o 50 | ``` 51 | dumpdecrypted.dylib 就是我们需要使用到的砸壳工具。 52 | 53 | ### 2.2. 连接越狱设备 54 | `ssh` 远程登入越狱设备 55 | ``` 56 | $ ssh root@192.168.1.183 57 | ``` 58 | 59 | 使用 `scp` 命令实现电脑与越狱设备之间相互传输文件 60 | ``` 61 | // 越狱设备 -> 电脑 62 | $ scp root@192.168.1.183:/var/mobile/Containers/Data/Application/5695E941-F58D-4775-AFD4-9D5883CBE3F8/Documents/kunlun.sqlite ./tmp 63 | 64 | // 电脑 -> 越狱设备 65 | $ scp ./1.txt root@192.168.1.183:/var/mobile/Containers/Data/Application/5695E941-F58D-4775-AFD4-9D5883CBE3F8/Documents 66 | ``` 67 | 68 | ### 2.3. 找到可执行文件的位置 69 | 70 | 以饿了么为例。手机启动饿了么,使用 `ps ax` 查看当前执行的进程: 71 | ``` 72 | $ ps ax | grep eleme.app 73 | 3468 ?? Ss 0:01.83 /var/containers/Bundle/Application/4FB489D8-2E7A-4F17-AAB0-670D2C5CF488/eleme.app/eleme 74 | ``` 75 | 76 | ### 2.4. 执行砸壳 77 | 78 | Killed 9 问题的解决方案:[传送门](https://github.com/stefanesser/dumpdecrypted/issues/19) 见 n8r0n commented on 15 Aug 2016 的回答 79 | 80 | 第一步,将 `dumpdecrypted.dylib` 文件拷贝到 `/usr/lib` 目录下。 81 | 82 | 第二步,切换用户至 mobile。 83 | ``` 84 | su mobile 85 | ``` 86 | 87 | 第三步,跳转至 Documents 目录,我们会将砸壳后的应用都放在这个路径下。 88 | ``` 89 | cd /var/mobile/Documents 90 | ``` 91 | 92 | 第四步,砸壳。 93 | ``` 94 | $ DYLD_INSERT_LIBRARIES=/usr/lib/dumpdecrypted.dylib /var/containers/Bundle/Application/4FB489D8-2E7A-4F17-AAB0-670D2C5CF488/eleme.app/eleme 95 | 96 | ach-o decryption dumper 97 | 98 | DISCLAIMER: This tool is only meant for security research purposes, not for application crackers. 99 | 100 | [+] detected 64bit ARM binary in memory. 101 | [+] offset to cryptid found: @0x10009cc58(from 0x10009c000) = c58 102 | [+] Found encrypted data at address 00004000 of length 11665408 bytes - type 1. 103 | [+] Opening /private/var/containers/Bundle/Application/4FB489D8-2E7A-4F17-AAB0-670D2C5CF488/eleme.app/eleme for reading. 104 | [+] Reading header 105 | [+] Detecting header type 106 | [+] Executable is a plain MACH-O image 107 | [+] Opening eleme.decrypted for writing. 108 | [+] Copying the not encrypted start of the file 109 | [+] Dumping the decrypted data into the file 110 | [+] Copying the not encrypted remainder of the file 111 | [+] Setting the LC_ENCRYPTION_INFO->cryptid to 0 at offset c58 112 | [+] Closing original file 113 | [+] Closing dump file 114 | ``` 115 | 116 | 如何砸壳成功,得到 `.decrypted` 文件 117 | ``` 118 | $ ls -l | grep eleme 119 | -rw-r--r-- 1 mobile mobile 15156032 Mar 30 13:20 eleme.decrypted 120 | ``` 121 | 122 | 最后一步,将 `.decrypted` 文件拷贝到电脑,准备进行 class-dump。 123 | 124 | ## 3. class-dump 125 | 126 | ``` 127 | $ class-dump -S -s -H eleme.decrypted -o Headers 128 | ``` 129 | class-dump 后生成的头文件会保存到 Headers 目录。 130 | 131 | ## 4. 参考资料 132 | 133 | 书籍 134 | - [《iOS应用逆向工程》](https://book.douban.com/subject/25826902/) by 沙梓社, 吴航, 刘瑾 135 | 136 | 文章 137 | - [iOS 逆向手把手教程之一:砸壳与class-dump](http://www.swiftyper.com/2016/05/02/iOS-reverse-step-by-step-part-1-class-dump/) by Swiftyper 2016 138 | - [逆向分析网络协议 iOS 篇](http://mp.weixin.qq.com/s?__biz=MzIwMTYzMzcwOQ==&mid=403204191&idx=1&sn=514664cc05597f8b76730cbf9f3a57f5&scene=4#wechat_redirect) by 糖炒小虾 139 | - [别人的 App 不好用?自己改了便是。Moves 篇(上)](http://mp.weixin.qq.com/s?__biz=MzIwMTYzMzcwOQ==&mid=2650948304&idx=1&sn=f76e7b765a7fcabcb71d37052b46e489&scene=4#wechat_redirect) by 糖炒小虾 140 | - [别人的 App 不好用?自己改了便是。Moves 篇(下)](http://mp.weixin.qq.com/s?__biz=MzIwMTYzMzcwOQ==&mid=2650948316&idx=1&sn=584f6c7fe9bf07a28985ffe53da4927e&scene=4#wechat_redirect) by 糖炒小虾 141 | - [别人的 App 不好用?自己改了便是。嘿嘿嘿 篇](http://mp.weixin.qq.com/s?__biz=MzIwMTYzMzcwOQ==&mid=2650948334&idx=1&sn=941d616d25ed16d967595e652e6c4d3b&scene=4#wechat_redirect) by 糖炒小虾 142 | - [iOS逆向之分析微信导航栏实现](http://www.jianshu.com/p/a9cd03044a31) by hi_xgb 143 | -------------------------------------------------------------------------------- /Runloop.md: -------------------------------------------------------------------------------- 1 | # Runloop -------------------------------------------------------------------------------- /Singleton.md: -------------------------------------------------------------------------------- 1 | # Singleton 单例模式 2 | 3 | 最佳实践 4 | ``` Objective-C 5 | + (nonnull instancetype)sharedInstance { 6 | static dispatch_once_t onceToken; 7 | static id instance; 8 | dispatch_once(&onceToken, ^{ 9 | instance = [[self alloc] init]; 10 | }); 11 | return instance; 12 | } 13 | ``` 14 | 15 | 线程不安全 16 | ``` Objective-C 17 | + (id)sharedInstance { 18 | static id instance = nil; 19 | if (!instance) { 20 | instance = [[self alloc] init]; 21 | } 22 | return instance; 23 | } 24 | ``` 25 | 26 | 线程安全,但性能不如 dispatch_once 27 | ``` Objective-C 28 | + (id)sharedInstance { 29 | static id instance = nil; 30 | @synchronized(self) { 31 | if (!instance) { 32 | instance = [[self alloc] init]; 33 | } 34 | } 35 | return instance; 36 | } 37 | ``` -------------------------------------------------------------------------------- /Swift.md: -------------------------------------------------------------------------------- 1 | # Swift 4 2 | 3 | ## 1. 变量 & 常量 4 | 5 | ``` Swift 6 | // 常量 7 | let maximumNumberOfLoginAttempts = 10 8 | 9 | // 变量 10 | var currentLoginAttempt = 0 11 | 12 | // 声明常量或变量时可以指定类型,但一般不需要 13 | var welcomeMessage: String = "Hello" 14 | ``` 15 | 16 | ## 2. 基本数据类型 17 | 18 | ## 3. 操作符 19 | 20 | ## 4. 字符串 21 | 22 | ## 5. 集合类型 23 | 24 | Swift 提供三种基本集合类型:`Array`、`Set` 和 `Dictionary`。各自的特点如下: 25 | - Array - 有序、可重复 26 | - Set - 无序、不重复 27 | - Dictionary - 无序、键值对结构 28 | 29 | ### 5.1. 数组 Array 30 | 31 | ``` Swift 32 | // 创建数组 33 | let strarr = ["a", "b", "c"] 34 | 35 | // 创建空数组,必须指定类型 36 | let array = [] // !error: empty collection literal requires an explicit type 37 | let strarr:[String] = [] // best 38 | let strarr = [String]() 39 | let strarr: Array = Array() 40 | 41 | // 创建带默认值的数组 42 | let strarr = Array(repeating:"", count:3) // ["", "", ""] 43 | 44 | // 合并数组 45 | let strarr1 = ["a", "b", "c"] 46 | let strarr2 = ["d", "e", "f"] 47 | let strarr3 = strarr1 + strarr2 // ["a", "b", "c", "d", "e", "f"] 48 | 49 | // 数组判空 50 | [].isEmpty // 官方推荐使用 isEmpty,不要使用 [].count==0 51 | 52 | // 加元素 53 | var array = ["a"] // ["a"] 54 | array.append("b") // ["a", "b"] 55 | array.append(contentsOf: ["c", "d"]) // ["a", "b", "c", "d"] 56 | array += ["e", "f"] // ["a", "b", "c", "d", "e", "f"] 57 | array.insert("x", at: 2) // ["a", "b", "x", "c", "d", "e", "f"] 58 | array.insert(contentsOf: ["x0", "x1", "x2"], at: 2) // ["a", "b", "x0", "x1", "x2", "x", "c", "d", "e", "f"] 59 | 60 | // 删元素 61 | var array = ["a", "b", "c", "d", "e"] 62 | array.removeFirst() // return "a" 63 | array.removeLast() // return "e" 64 | array.remove(at: 1) // return "c" 65 | array.removeAll() // no return 66 | 67 | // 改元素 68 | var array = ["a", "b", "c", "d", "e"] 69 | array[0] = "a0" // ["a0", "b", "c", "d", "e"] 70 | 71 | // 读元素 72 | let array = ["a", "b", "c", "d", "e"] 73 | let str0 = array[0] // "a" 74 | 75 | // 数组切片,返回值类型为 ArraySlice 而不是 Array 76 | let slice1 = array[1...3] // ["b", "c", "d"] 77 | let slice2 = array[1.. Bool in number > 10 } // return true 92 | numbers.first { (number) -> Bool in number > 1 } // return 10 93 | numbers.first { (number) -> Bool in number < 0 } // return nil 94 | numbers.index(of: 100) // return 3 95 | numbers.index(of: -1) // return nil 96 | numbers.index { (number) -> Bool in number > 10 } // return 3 97 | ``` 98 | 99 | ### 5.2. 集合 Set 100 | 101 | #### 5.2.1. 有序集合 SortedSet 102 | 103 | ### 5.3. 字典 Dictionary 104 | 105 | ### 5.4. 写时复制特性(copy-on-write) 106 | 107 | ## 6. 控制流 108 | 109 | for-in 110 | 111 | while 112 | repeat-while 113 | 114 | if 115 | 116 | switch 117 | 118 | guard 119 | 120 | ## 7. 函数 Function 121 | 122 | ## 8. 闭包 Closure 123 | 124 | ## 9. 类 & 结构体 & 对象 125 | 126 | ## 10. 错误处理 Error Handling 127 | 128 | ## 11. 编码风格 129 | - [GitHub's Swift Style Guide](https://github.com/github/swift-style-guide) 130 | - [SwiftLint](https://github.com/realm/SwiftLint) 131 | 132 | ## 12. 参考资料 133 | 134 | - [Swift 官网](https://swift.org) 135 | - [The Swift Programming Language (Swift 4 Edition)](https://swift.org/documentation/TheSwiftProgrammingLanguage(Swift4).epub) 136 | - [The Swift Programming Language 中文版](https://github.com/numbbbbb/the-swift-programming-language-in-chinese) 目前已经更新到 Swift 3.0。 2016-09-23 137 | - [《Swifter - Swift 开发者必备 Tips》](https://objccn.io/products/swifter-tips) 138 | - [《Swift 进阶》](https://objccn.io/products/advanced-swift/) 139 | - [《函数式 Swift》](https://objccn.io/products/functional-swift/) 140 | - [《集合类型优化》](https://objccn.io/products/optimizing-collections/) 141 | -------------------------------------------------------------------------------- /Time.md: -------------------------------------------------------------------------------- 1 | # Time 2 | 3 | ## 1. API 4 | 5 | ### 1.1. NSDate 6 | 7 | ### 1.2. CFAbsoluteTimeGetCurrent() 8 | 9 | ### 1.3. CACurrentMediaTime() 10 | 11 | ### 1.4. mach_absolute_time() 12 | 13 | ## 2. benchmark 14 | 15 | 单位:毫秒(ms) 16 | 17 | ## 3. Ref 18 | - [iOS 关于时间的处理](http://mrpeak.cn/blog/ios-time/) by MrPeak 2016 -------------------------------------------------------------------------------- /TypeScript.md: -------------------------------------------------------------------------------- 1 | # TypeScript 2 | 3 | ## 1. 工程配置 4 | 5 | ### 1.1. tsconfig.json 6 | 7 | ## 2. 语法 8 | 9 | ### 2.1. Basic Types 基本类型 10 | 11 | ### 2.2. Interfaces 接口 12 | 13 | ### 2.3. Functions 函数 14 | 15 | ### 2.4. Generics 泛型 16 | 17 | ### 2.5. Enums 枚举 18 | 19 | ## 3. Ref 20 | - [www.typescriptlang.org](https://www.typescriptlang.org/index.html) -------------------------------------------------------------------------------- /WeChatTech.md: -------------------------------------------------------------------------------- 1 | # 微信背后的技术 2 | 3 | ## 技术团队 4 | - [微信读书技术团队](http://wereadteam.github.io) 5 | 6 | ## 文章 7 | - [每日数亿次微信视频通话背后,靠什么技术支撑?](http://www.infoq.com/cn/articles/wechat-video-call) 8 | 9 | ## 开源项目 10 | - [mars](https://github.com/Tencent/mars) - Mars is a cross-platform network component developed by WeChat. 11 | - [WCDB](https://github.com/Tencent/wcdb) - WCDB is a cross-platform database framework developed by WeChat. -------------------------------------------------------------------------------- /Weex.md: -------------------------------------------------------------------------------- 1 | # Weex 2 | 3 | 4 | 5 | - [1. 初见](#1-初见) 6 | - [1.1. Weex 是什么?](#11-weex-是什么) 7 | - [1.2. Weex 的目标是什么?](#12-weex-的目标是什么) 8 | - [1.3. 学习 Weex 之前,你需要了解什么?](#13-学习-weex-之前你需要了解什么) 9 | - [2. 搭建开发环境](#2-搭建开发环境) 10 | - [3. hello-weex](#3-hello-weex) 11 | - [3.1. 新建 Weex 工程](#31-新建-weex-工程) 12 | - [3.2. Weex 工程标准结构](#32-weex-工程标准结构) 13 | - [3.3. 安装依赖](#33-安装依赖) 14 | - [3.4. 构建](#34-构建) 15 | - [3.5. 部署并启动本地服务器](#35-部署并启动本地服务器) 16 | - [3.6. hello-weex for iOS](#36-hello-weex-for-ios) 17 | - [3.6.1. 通过 CocoaPods 安装 WeexSDK](#361-通过-cocoapods-安装-weexsdk) 18 | - [3.6.2. 初始化 Weex 环境](#362-初始化-weex-环境) 19 | - [3.6.3. 渲染页面](#363-渲染页面) 20 | - [3.7. hello-weex for Android](#37-hello-weex-for-android) 21 | - [3.7.1. 新建工程,设置依赖](#371-新建工程设置依赖) 22 | - [3.7.2. 新建 ImageAdapter](#372-新建-imageadapter) 23 | - [3.7.3. 新建 WeexApplication](#373-新建-weexapplication) 24 | - [3.7.4. 修改 AndroidManifest.xml 启用 WeexApplication](#374-修改-androidmanifestxml-启用-weexapplication) 25 | - [3.7.5. MainActivity](#375-mainactivity) 26 | - [4. 工作原理](#4-工作原理) 27 | - [5. 参考资料](#5-参考资料) 28 | 29 | 30 | 31 | ## 1. 初见 32 | 33 | ### 1.1. Weex 是什么? 34 | - 一套跨平台开发方案(iOS、Android、浏览器三端) 35 | - 对移动端而言,可以用 web 的开发体验构建高性能、可扩展的 native 应用 36 | - 支持 Vue.js 37 | 38 | ### 1.2. Weex 的目标是什么? 39 | - Write Once, Run Everywhere. 40 | - 一套代码同时支持 iOS、Android、浏览器(H5)三端运行 41 | - 打造三端一致的 native 应用 42 | 43 | ### 1.3. 学习 Weex 之前,你需要了解什么? 44 | - Node.js 45 | - HTML + CSS + JavaScript 前端知识 46 | - Vue.js 框架 47 | - iOS 或 Android Native 知识 48 | 49 | ## 2. 搭建开发环境 50 | - [dotWe](http://dotwe.org/vue) - Weex 在线调试工具 51 | - Node.js & npm 52 | - weex-toolkit - 一个基于 Node.js 的命令行工具(注:1.0.1 之后才支持初始化 Vue 项目) 53 | 54 | ## 3. hello-weex 55 | 56 | ### 3.1. 新建 Weex 工程 57 | ``` 58 | $ weex init hello-weex 59 | 60 | prompt: Init your Project: (hello-weex) 61 | file: /Users/jiyixuan/weex_workspace/hello-weex/.babelrc created. 62 | file: /Users/jiyixuan/weex_workspace/hello-weex/.eslintrc created. 63 | file: /Users/jiyixuan/weex_workspace/hello-weex/.gitignore created. 64 | file: /Users/jiyixuan/weex_workspace/hello-weex/README.md created. 65 | file: /Users/jiyixuan/weex_workspace/hello-weex/app.js created. 66 | file: /Users/jiyixuan/weex_workspace/hello-weex/assets/phantom-limb.js created. 67 | file: /Users/jiyixuan/weex_workspace/hello-weex/assets/qrcode.js created. 68 | file: /Users/jiyixuan/weex_workspace/hello-weex/assets/qrcode.min.js created. 69 | file: /Users/jiyixuan/weex_workspace/hello-weex/assets/style.css created. 70 | file: /Users/jiyixuan/weex_workspace/hello-weex/assets/url.js created. 71 | file: /Users/jiyixuan/weex_workspace/hello-weex/build/init.js created. 72 | file: /Users/jiyixuan/weex_workspace/hello-weex/index.html created. 73 | file: /Users/jiyixuan/weex_workspace/hello-weex/package.json created. 74 | file: /Users/jiyixuan/weex_workspace/hello-weex/src/foo.vue created. 75 | file: /Users/jiyixuan/weex_workspace/hello-weex/webpack.config.js created. 76 | file: /Users/jiyixuan/weex_workspace/hello-weex/weex.html created. 77 | ``` 78 | 79 | ### 3.2. Weex 工程标准结构 80 | ``` 81 | ├── README.md 82 | ├── app.js // 默认入口 83 | ├── assets 84 | │   ├── phantom-limb.js 85 | │   ├── qrcode.js 86 | │   ├── qrcode.min.js 87 | │   ├── style.css 88 | │   └── url.js 89 | ├── build 90 | │   └── init.js 91 | ├── index.html 92 | ├── package.json // npm 配置文件,执行 npm install 命令时会根据该文件配置来安装依赖 93 | ├── src 94 | │   └── foo.vue 95 | ├── webpack.config.js // webpack 配置文件 96 | └── weex.html 97 | ``` 98 | 99 | src/foo.vue 100 | ``` 101 | 107 | 108 | 113 | 114 | 128 | ``` 129 | 130 | ### 3.3. 安装依赖 131 | 132 | ``` 133 | $ npm install 134 | ``` 135 | 根据 `package.json` 配置安装依赖包到当前目录。若当前目录下没有 node_modules 文件夹,则新建一个。 136 | 137 | ### 3.4. 构建 138 | 139 | ``` 140 | $ npm run dev 141 | 142 | > hello-weex@0.1.0 dev /Users/jiyixuan/weex_workspace/hello-weex 143 | > webpack --watch 144 | 145 | Hash: 341195b95f4773f47824 146 | Version: webpack 1.14.0 147 | Time: 1037ms 148 | Asset Size Chunks Chunk Names 149 | app.weex.js 4.41 kB 0 [emitted] app 150 | + 5 hidden modules 151 | Hash: 4356d9addcb039cb794d 152 | Version: webpack 1.14.0 153 | Time: 1121ms 154 | Asset Size Chunks Chunk Names 155 | app.web.js 15.4 kB 0 [emitted] app 156 | + 10 hidden modules 157 | ``` 158 | 159 | > `npm run` 命令是 `npm run-script` 的简写,详见: [https://docs.npmjs.com/cli/run-script](https://docs.npmjs.com/cli/run-script) 160 | 161 | `npm run dev` 命令的作用是执行一个名为 `dev` 的脚本。可以被执行的脚本还有很多,都被定义在了 `package.json` 配置文件中: 162 | 163 | ``` 164 | ... 165 | // 默认定义了四种可执行脚本:build、dev、serve、debug。我们还可以根据自己的需求扩展。 166 | "scripts": { 167 | "build": "webpack", 168 | "dev": "webpack --watch", 169 | "serve": "node build/init.js && serve -p 8080", 170 | "debug": "weex-devtool" 171 | }, 172 | 173 | ... 174 | ``` 175 | 176 | 从上面的定义可以看出,执行 `npm run dev` 等价于执行 `webpack --watch`。`--watch` 的作用是当修改 `.vue` 的源码时,webpack 将自动帮你构建一次。 177 | > 注:要想执行 `webpack` 命令必须首先通过 `npm install wepback -g` 全局安装 wepback。详见: [https://docs.npmjs.com/cli/install](https://docs.npmjs.com/cli/install) 178 | 179 | 构建的结果是在根目录下会生成一个 dist 文件夹: 180 | ``` 181 | dist 182 | ├── app.web.js // 浏览器端用 183 | └── app.weex.js // 移动端用 184 | ``` 185 | 186 | ### 3.5. 部署并启动本地服务器 187 | 188 | 运行 `npm run serve` 启动服务器 189 | 190 | ``` 191 | $ npm run serve 192 | 193 | > hello-weex@0.1.0 serve /Users/jiyixuan/weex_workspace/hello-weex 194 | > node build/init.js && serve -p 8080 195 | 196 | serving /Users/jiyixuan/weex_workspace/hello-weex on port 8080 197 | GET /index.html 200 9ms - 1.6kb 198 | GET /config.js 200 3ms - 32 199 | GET /assets/style.css 200 8ms - 1.14kb 200 | GET /assets/url.js 200 5ms - 295 201 | GET /assets/qrcode.js 200 4ms - 48.89kb 202 | GET /node_modules/vue/dist/vue.js 200 5ms - 238.7kb 203 | GET /weex.html 200 1ms - 891 204 | GET /assets/phantom-limb.js 200 6ms - 10.12kb 205 | GET /dist/app.web.js 200 5ms - 15.02kb 206 | GET /node_modules/vue/dist/vue.runtime.js 200 6ms - 172.52kb 207 | GET /node_modules/weex-vue-render/index.js 200 7ms - 713.49kb 208 | GET /weex.html 304 1ms 209 | ``` 210 | 211 | 浏览器打开 `http://localhost:8080/index.html` 查看 Weex h5 页面 212 | 213 | ### 3.6. hello-weex for iOS 214 | 215 | #### 3.6.1. 通过 CocoaPods 安装 WeexSDK 216 | 常规做法,没什么要特别说明的。 217 | 218 | #### 3.6.2. 初始化 Weex 环境 219 | 220 | ``` Objective-C 221 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 222 | { 223 | // 配置 224 | [WXAppConfiguration setAppGroup:@"study-weex"]; 225 | [WXAppConfiguration setAppName:@"hello-weex-ios"]; 226 | [WXAppConfiguration setAppVersion:@"1.0.0"]; 227 | 228 | // 初始化 SDK 229 | [WXSDKEngine initSDKEnvironment]; 230 | 231 | // 设置日志 232 | [WXLog setLogLevel: WXLogLevelAll]; 233 | 234 | return YES; 235 | } 236 | ``` 237 | 238 | #### 3.6.3. 渲染页面 239 | 240 | ``` Objective-C 241 | #import "ViewController.h" 242 | // 3rd 243 | #import 244 | 245 | @interface ViewController () 246 | 247 | @property (nonatomic, strong) NSURL *url; 248 | @property (nonatomic, strong) WXSDKInstance *instance; 249 | @property (nonatomic, strong) UIView *weexView; 250 | 251 | @end 252 | 253 | @implementation ViewController 254 | 255 | - (void)viewDidLoad 256 | { 257 | [super viewDidLoad]; 258 | 259 | _url = [NSURL URLWithString:@"http://192.168.1.186:8080/dist/app.weex.js"]; 260 | 261 | _instance = [[WXSDKInstance alloc] init]; 262 | _instance.viewController = self; 263 | _instance.frame = self.view.frame; 264 | 265 | __weak typeof(self) weakSelf = self; 266 | _instance.onCreate = ^(UIView *view) { 267 | [weakSelf.weexView removeFromSuperview]; 268 | weakSelf.weexView = view; // 官方文档里少了这句,会导致看不到界面 269 | [weakSelf.view addSubview:weakSelf.weexView]; 270 | }; 271 | 272 | _instance.onFailed = ^(NSError *error) { 273 | // process failure 274 | }; 275 | 276 | _instance.renderFinish = ^ (UIView *view) { 277 | // process renderFinish 278 | }; 279 | [_instance renderWithURL:self.url options:@{@"bundleUrl":[self.url absoluteString]} data:nil]; 280 | } 281 | 282 | - (void)didReceiveMemoryWarning 283 | { 284 | [super didReceiveMemoryWarning]; 285 | // Dispose of any resources that can be recreated. 286 | } 287 | 288 | - (void)dealloc 289 | { 290 | // 销毁掉 Weex instance,释放内存,避免造成内存泄露 291 | [_instance destroyInstance]; 292 | } 293 | 294 | @end 295 | ``` 296 | 297 | ### 3.7. hello-weex for Android 298 | 299 | #### 3.7.1. 新建工程,设置依赖 300 | app/build.gradle 301 | ``` 302 | apply plugin: 'com.android.application' 303 | 304 | android { 305 | compileSdkVersion 23 306 | buildToolsVersion "25.0.2" 307 | defaultConfig { 308 | applicationId "android.neegle.net.helloweexandroid" 309 | minSdkVersion 15 310 | targetSdkVersion 23 311 | versionCode 1 312 | versionName "1.0" 313 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 314 | } 315 | buildTypes { 316 | release { 317 | minifyEnabled false 318 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 319 | } 320 | } 321 | } 322 | 323 | dependencies { 324 | compile fileTree(dir: 'libs', include: ['*.jar']) 325 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 326 | exclude group: 'com.android.support', module: 'support-annotations' 327 | }) 328 | compile 'com.android.support:appcompat-v7:23.1.1' 329 | compile 'com.android.support:recyclerview-v7:23.1.1' 330 | compile 'com.android.support:support-v4:23.1.1' 331 | compile 'com.android.support:appcompat-v7:23.1.1' 332 | compile 'com.alibaba:fastjson:1.1.46.android' 333 | compile 'com.taobao.android:weex_sdk:0.10.0' // 0.10.0 以上版本才支持 Vue.js 334 | testCompile 'junit:junit:4.12' 335 | } 336 | ``` 337 | 338 | #### 3.7.2. 新建 ImageAdapter 339 | ``` Java 340 | import android.widget.ImageView; 341 | 342 | import com.taobao.weex.adapter.IWXImgLoaderAdapter; 343 | import com.taobao.weex.common.WXImageStrategy; 344 | import com.taobao.weex.dom.WXImageQuality; 345 | 346 | /** 347 | * Created by jiyixuan on 2017/3/29. 348 | */ 349 | 350 | public class ImageAdapter implements IWXImgLoaderAdapter { 351 | 352 | @Override 353 | public void setImage(String url, ImageView view, WXImageQuality quality, WXImageStrategy strategy) { 354 | //实现你自己的图片下载。 355 | } 356 | } 357 | ``` 358 | 359 | #### 3.7.3. 新建 WeexApplication 360 | ``` Java 361 | import android.app.Application; 362 | 363 | import com.taobao.weex.InitConfig; 364 | import com.taobao.weex.WXSDKEngine; 365 | import com.taobao.weex.common.WXException; 366 | 367 | /** 368 | * Created by jiyixuan on 2017/3/29. 369 | */ 370 | 371 | public class WeexApplication extends Application { 372 | 373 | @Override 374 | public void onCreate() { 375 | super.onCreate(); 376 | InitConfig config = new InitConfig.Builder().setImgAdapter(new ImageAdapter()).build(); 377 | WXSDKEngine.initialize(this, config); 378 | } 379 | } 380 | ``` 381 | #### 3.7.4. 修改 AndroidManifest.xml 启用 WeexApplication 382 | ``` 383 | 384 | 386 | 387 | 388 | 389 | 390 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | ``` 407 | 408 | #### 3.7.5. MainActivity 409 | ``` 410 | package android.neegle.net.helloweexandroid; 411 | 412 | import android.support.v7.app.AppCompatActivity; 413 | import android.os.Bundle; 414 | import android.view.View; 415 | 416 | import com.taobao.weex.IWXRenderListener; 417 | import com.taobao.weex.WXSDKInstance; 418 | import com.taobao.weex.common.WXRenderStrategy; 419 | import com.taobao.weex.utils.WXFileUtils; 420 | 421 | import java.util.HashMap; 422 | import java.util.Map; 423 | 424 | public class MainActivity extends AppCompatActivity implements IWXRenderListener { 425 | 426 | private static final String WEB_URL="http://192.168.1.186:8080/dist/app.weex.js"; 427 | WXSDKInstance mWXSDKInstance; 428 | 429 | @Override 430 | protected void onCreate(Bundle savedInstanceState) { 431 | super.onCreate(savedInstanceState); 432 | setContentView(R.layout.activity_main); 433 | 434 | mWXSDKInstance = new WXSDKInstance(this); 435 | mWXSDKInstance.registerRenderListener(this); 436 | 437 | Map options = new HashMap<>(); 438 | // 加载服务器 js 439 | // options.put(WXSDKInstance.BUNDLE_URL, WEB_URL); 440 | // mWXSDKInstance.render("WXSample",WEB_URL,options, null, WXRenderStrategy.APPEND_ONCE); 441 | // 加载本地 js 442 | options.put(WXSDKInstance.BUNDLE_URL, "file://build/hello.js"); 443 | mWXSDKInstance.render("WXSample",WXFileUtils.loadAsset("build/app.weex.js", this),options, null, WXRenderStrategy.APPEND_ONCE); 444 | } 445 | 446 | @Override 447 | public void onViewCreated(WXSDKInstance instance, View view) { 448 | setContentView(view); 449 | } 450 | 451 | @Override 452 | public void onRenderSuccess(WXSDKInstance instance, int width, int height) { 453 | } 454 | @Override 455 | public void onRefreshSuccess(WXSDKInstance instance, int width, int height) { 456 | } 457 | @Override 458 | public void onException(WXSDKInstance instance, String errCode, String msg) { 459 | } 460 | 461 | @Override 462 | protected void onResume() { 463 | super.onResume(); 464 | if(mWXSDKInstance!=null){ 465 | mWXSDKInstance.onActivityResume(); 466 | } 467 | } 468 | 469 | @Override 470 | protected void onPause() { 471 | super.onPause(); 472 | if(mWXSDKInstance!=null){ 473 | mWXSDKInstance.onActivityPause(); 474 | } 475 | } 476 | @Override 477 | protected void onStop() { 478 | super.onStop(); 479 | if(mWXSDKInstance!=null){ 480 | mWXSDKInstance.onActivityStop(); 481 | } 482 | } 483 | @Override 484 | protected void onDestroy() { 485 | super.onDestroy(); 486 | if(mWXSDKInstance!=null){ 487 | mWXSDKInstance.onActivityDestroy(); 488 | } 489 | } 490 | } 491 | ``` 492 | 493 | ## 4. 工作原理 494 | 495 | ## 5. 参考资料 496 | - [weex 官网](http://weex.apache.org/cn/) 497 | - [Vue.js 官网](https://vuejs.org) 498 | - [Weex 是如何在 iOS 客户端上跑起来的](http://www.jianshu.com/p/41cde2c62b81) by 一缕殇流化隐半边冰霜 2017 499 | - [由FlexBox算法强力驱动的Weex布局引擎](http://www.jianshu.com/p/d085032d4788) by 一缕殇流化隐半边冰霜 2017 500 | -------------------------------------------------------------------------------- /lldb.md: -------------------------------------------------------------------------------- 1 | # LLDB 2 | 3 | ``` 4 | Debugger commands: 5 | apropos -- List debugger commands related to a word or subject. 6 | breakpoint -- Commands for operating on breakpoints (see 'help b' for 7 | shorthand.) 8 | bugreport -- Commands for creating domain-specific bug reports. 9 | command -- Commands for managing custom LLDB commands. 10 | disassemble -- Disassemble specified instructions in the current 11 | target. Defaults to the current function for the 12 | current thread and stack frame. 13 | expression -- Evaluate an expression on the current thread. Displays 14 | any returned value with LLDB's default formatting. 15 | frame -- Commands for selecting and examing the current thread's 16 | stack frames. 17 | gdb-remote -- Connect to a process via remote GDB server. If no host 18 | is specifed, localhost is assumed. 19 | gui -- Switch into the curses based GUI mode. 20 | help -- Show a list of all debugger commands, or give details 21 | about a specific command. 22 | kdp-remote -- Connect to a process via remote KDP server. If no UDP 23 | port is specified, port 41139 is assumed. 24 | language -- Commands specific to a source language. 25 | log -- Commands controlling LLDB internal logging. 26 | memory -- Commands for operating on memory in the current target 27 | process. 28 | platform -- Commands to manage and create platforms. 29 | plugin -- Commands for managing LLDB plugins. 30 | process -- Commands for interacting with processes on the current 31 | platform. 32 | quit -- Quit the LLDB debugger. 33 | register -- Commands to access registers for the current thread and 34 | stack frame. 35 | script -- Invoke the script interpreter with provided code and 36 | display any results. Start the interactive interpreter 37 | if no code is supplied. 38 | settings -- Commands for managing LLDB settings. 39 | source -- Commands for examining source code described by debug 40 | information for the current target process. 41 | target -- Commands for operating on debugger targets. 42 | thread -- Commands for operating on one or more threads in the 43 | current process. 44 | type -- Commands for operating on the type system. 45 | version -- Show the LLDB debugger version. 46 | watchpoint -- Commands for operating on watchpoints. 47 | 48 | Current command abbreviations (type 'help command alias' for more info): 49 | add-dsym -- Add a debug symbol file to one of the target's current modules 50 | by specifying a path to a debug symbols file, or using the 51 | options to specify a module to download symbols for. 52 | attach -- Attach to process by ID or name. 53 | b -- Set a breakpoint using one of several shorthand formats. 54 | bt -- Show the current thread's call stack. Any numeric argument 55 | displays at most that many frames. The argument 'all' displays 56 | all threads. 57 | c -- Continue execution of all threads in the current process. 58 | call -- Evaluate an expression on the current thread. Displays any 59 | returned value with LLDB's default formatting. 60 | continue -- Continue execution of all threads in the current process. 61 | detach -- Detach from the current target process. 62 | di -- Disassemble specified instructions in the current target. 63 | Defaults to the current function for the current thread and 64 | stack frame. 65 | dis -- Disassemble specified instructions in the current target. 66 | Defaults to the current function for the current thread and 67 | stack frame. 68 | display -- Evaluate an expression at every stop (see 'help target 69 | stop-hook'.) 70 | down -- Select a newer stack frame. Defaults to moving one frame, a 71 | numeric argument can specify an arbitrary number. 72 | env -- Shorthand for viewing and setting environment variables. 73 | exit -- Quit the LLDB debugger. 74 | f -- Select the current stack frame by index from within the current 75 | thread (see 'thread backtrace'.) 76 | file -- Create a target using the argument as the main executable. 77 | finish -- Finish executing the current stack frame and stop after 78 | returning. Defaults to current thread unless specified. 79 | image -- Commands for accessing information for one or more target 80 | modules. 81 | j -- Set the program counter to a new address. 82 | jump -- Set the program counter to a new address. 83 | kill -- Terminate the current target process. 84 | l -- List relevant source code using one of several shorthand formats. 85 | list -- List relevant source code using one of several shorthand formats. 86 | n -- Source level single step, stepping over calls. Defaults to 87 | current thread unless specified. 88 | next -- Source level single step, stepping over calls. Defaults to 89 | current thread unless specified. 90 | nexti -- Instruction level single step, stepping over calls. Defaults to 91 | current thread unless specified. 92 | ni -- Instruction level single step, stepping over calls. Defaults to 93 | current thread unless specified. 94 | p -- Evaluate an expression on the current thread. Displays any 95 | returned value with LLDB's default formatting. 96 | parray -- Evaluate an expression on the current thread. Displays any 97 | returned value with LLDB's default formatting. 98 | po -- Evaluate an expression on the current thread. Displays any 99 | returned value with formatting controlled by the type's author. 100 | poarray -- Evaluate an expression on the current thread. Displays any 101 | returned value with LLDB's default formatting. 102 | print -- Evaluate an expression on the current thread. Displays any 103 | returned value with LLDB's default formatting. 104 | q -- Quit the LLDB debugger. 105 | r -- Launch the executable in the debugger. 106 | rbreak -- Sets a breakpoint or set of breakpoints in the executable. 107 | repl -- Evaluate an expression on the current thread. Displays any 108 | returned value with LLDB's default formatting. 109 | run -- Launch the executable in the debugger. 110 | s -- Source level single step, stepping into calls. Defaults to 111 | current thread unless specified. 112 | si -- Instruction level single step, stepping into calls. Defaults to 113 | current thread unless specified. 114 | sif -- Step through the current block, stopping if you step directly 115 | into a function whose name matches the TargetFunctionName. 116 | step -- Source level single step, stepping into calls. Defaults to 117 | current thread unless specified. 118 | stepi -- Instruction level single step, stepping into calls. Defaults to 119 | current thread unless specified. 120 | t -- Change the currently selected thread. 121 | tbreak -- Set a one-shot breakpoint using one of several shorthand 122 | formats. 123 | undisplay -- Stop displaying expression at every stop (specified by stop-hook 124 | index.) 125 | up -- Select an older stack frame. Defaults to moving one frame, a 126 | numeric argument can specify an arbitrary number. 127 | x -- Read from the memory of the current target process. 128 | 129 | For more information on any command, type 'help '. 130 | ``` -------------------------------------------------------------------------------- /编程语言/Objective-C/Effective_Objective-C_2.0_读书笔记.md: -------------------------------------------------------------------------------- 1 | # Effective Objective-C 2.0 读书笔记 2 | 3 | ## Accustoming Yourself to Objective-C 4 | 熟悉 Objective-C 5 | 6 | ### \# 01. Familiarize Yourself with Objective-C's Roots 7 | 了解 Objective-C 语言的起源 8 | 9 | Objective-C = C + Runtime 10 | 11 | Objective-C 的消息传递机制(Messaging) vs C++ 的函数调用机制(Function calling) 12 | - 消息传递:**运行时**决定方法执行的具体行为 13 | - 函数调用:**编译时**决定方法执行的具体行为 14 | - 思考:Objective-C 和 C++ 分别是如何实现多态的? 15 | 16 | ``` 17 | // Messaging (Objective-C) 18 | Object *obj = [Object new]; 19 | [obj performWith:parameter1 and:parameter2]; 20 | 21 | // Function calling (C++) 22 | Object *obj = new Object(); 23 | obj->(parameter1, parameter2); 24 | ``` 25 | 26 | Objective-C 中的数据类型 27 | - 非对象类型,比如 int, float, double 28 | - C 结构体,比如 CGRect 29 | - Objective-C 对象,比如 NSString 30 | 31 | Objective-C 的内存模型 32 | - 栈内存:非对象类型、C 结构体、指针 33 | - 下开口,即高地址往下减 34 | - 堆内存:Objective-C 对象 35 | - 低地址往上加 36 | - 指针 37 | - 32位架构下,占4字节 38 | - 64位架构下,占8字节 39 | 40 | ``` 41 | // 64位环境 42 | int a = 1; 43 | NSString *str1 = @"abc"; 44 | NSString *str2 = @"abc"; 45 | NSString *str3 = @"xyz"; 46 | 47 | NSLog(@"%p", str1); // 0x100001038 48 | NSLog(@"%p", str2); // 0x100001038 49 | NSLog(@"%p", str3); // 0x100001058 50 | NSLog(@"%p", &a); // 0x7fff5fbff80c 51 | NSLog(@"%p", &str1); // 0x7fff5fbff800 52 | NSLog(@"%p", &str2); // 0x7fff5fbff7f8 53 | NSLog(@"%p", &str3); // 0x7fff5fbff7f0 54 | ``` 55 | 56 | ### \# 02. Minimize Importing Headers in Headers 57 | 在头文件中尽量少引入其他头文件 58 | 59 | ### \# 03. Prefer Literal Syntax over the Equivalent Methods 60 | 多用字面量语法,少用与之等价的方法 61 | 62 | ### \# 04. Prefer Typed Constants to Preprocessor define 63 | 多用类型常量,少用预编译指令 64 | 65 | ### \# 05. Use Enumerations for States, Options, and Status Codes 66 | 使用枚举表示状态、选项和状态码 67 | 68 | ## Objects, Messaging, and the Runtime 69 | 对象、消息和运行时 70 | 71 | ### \# 6. Understand Properties 72 | 理解属性 73 | 74 | ### \# 7. Access Instance Variables Primarily Directly When Accessing Them Internally 75 | 对象内部尽量直接访问实例变量 76 | 77 | ### \# 8. Understand Object Equality 78 | 理解对象相等 79 | 80 | ### \# 9. Use the Class Cluster Pattern to Hide Implementation Detail 81 | 使用类族模式隐藏实现细节 82 | 83 | ### \# 10. Use Associated Objects to Attach Custom Data to Existing Classes 84 | 使用关联对象在既有类上附加自定义数据 85 | 86 | ### \# 11. Understand the Role of objc_msgSend 87 | 理解 objc_msgSend 的作用 88 | 89 | ### \# 12. Understand Message Forwarding 90 | 理解消息转发 91 | 92 | ### \# 13. Consider Method Swizzling to Debug Opaque Methods 93 | 使用 Method Swizzling 调试黑盒方法 94 | 95 | ### \# 14. Understand What a Class Object Is 96 | 理解类对象是什么 97 | 98 | ## Interface and API Design 99 | 接口与 API 设计 100 | 101 | ### \# 15. Use Prefix Names to Avoid Namespace Clashes 102 | 使用前缀避免命名空间冲突 103 | 104 | ### \# 16. Have a Designated Initializer 105 | 提供 Designated Initializer 106 | 107 | ### \# 17. Implement the description Method 108 | 实现 description 方法 109 | 110 | ### \# 18. Prefer Immutable Objects 111 | 尽量使用不可变对象 112 | 113 | ### \# 19. Use Clear and Consistent Naming 114 | 使用清晰并一致的命名方式 115 | 116 | ### \# 20. Prefix Private Method Names 117 | 私有方法命名加前缀 118 | 119 | ### \# 21. Understand the Objective-C Error Model 120 | 理解 Objective-C 的错误模型 121 | 122 | ### \# 22. Understand the NSCopying Protocol 123 | 理解 NSCopying 协议 124 | 125 | ## Protocols and Categories 126 | 协议与分类 127 | 128 | ### \# 23. Use Delegate and Data Source Protocols for Inter-object Communication 129 | 使用委托与数据源协议进行对象间通讯 130 | 131 | ### \# 24. Use Categories to Break Class Implementations into Manageable Segments 132 | 133 | ### \# 25. Always Prefix Category Names on Third-Party Classes 134 | 135 | ### \# 26. Avoid Properties in Categories 136 | 137 | ### \# 27. Use the Class-Continuation Category to Hide Implementation Detail 138 | 139 | ### \# 28. Use a Protocol to Provide Anonymous Objects 140 | 141 | ## Memory Management 142 | ### \# 29. Understand Reference Counting 143 | ### \# 30. Use ARC to Make Reference Counting Easier 144 | ### \# 31. Release References and Clean Up Observation State Only in dealloc 145 | ### \# 32. Beware of Memory Management with Exception-Safe Code 146 | ### \# 33. Use Weak References to Avoid Retain Cycles 147 | ### \# 34. Use Autorelease Pool Blocks to Reduce High- Memory Waterline 148 | ### \# 35. Use Zombies to Help Debug Memory- Management Problems 149 | ### \# 36. Avoid Using retain Count 150 | 151 | ## Blocks and Grand Central Dispatch 152 | ### \# 37. Understand Blocks 153 | ### \# 38. Create typedefs for Common Block Types 154 | ### \# 39. Use Handler Blocks to Reduce Code Separation 155 | ### \# 40. Avoid Retain Cycles Introduced by Blocks Referencing the Object Owning Them 156 | ### \# 41. Prefer Dispatch Queues to Locks for Synchronization 157 | ### \# 42. Prefer GCD to performSelector and Friends 158 | ### \# 43. Know When to Use GCD and When to Use Operation Queues 159 | ### \# 44. Use Dispatch Groups to Take Advantage of Platform Scaling 160 | ### \# 45. Use dispatch_once for Thread-Safe Single-Time Code Execution 161 | ### \# 46. Avoid dispatch_get_current_queue 162 | 163 | ## The System Frameworks 164 | ### \# 47. Familiarize Yourself with the System Frameworks 165 | ### \# 48. Prefer Block Enumeration to for Loops 166 | ### \# 49. Use Toll-Free Bridging for Collections with Custom Memory-Management Semantics 167 | ### \# 50. Use NSCache Instead of NSDictionary for Caches 168 | ### \# 51. Keep initialize and load Implementations Lean 169 | ### \# 52. Remember that NSTimer Retains Its Target 170 | -------------------------------------------------------------------------------- /编程语言/Objective-C/README.md: -------------------------------------------------------------------------------- 1 | # Objective-C 2 | 3 | ## 我的笔记 4 | * [Effective Objective-C 2.0 读书笔记](Effective_Objective-C_2.0_读书笔记.md) 5 | 6 | ## 参考资料 7 | 8 | ### 书籍 9 | * [《Effective Objective-C 2.0》](https://book.douban.com/subject/25829244/) by Matt Galloway 10 | * [《Objective-C高级编程》](https://book.douban.com/subject/24720270/) by 坂本一树 / 古本智彦 11 | -------------------------------------------------------------------------------- /编程语言/README.md: -------------------------------------------------------------------------------- 1 | # 编程语言 2 | -------------------------------------------------------------------------------- /网络/HTTP/README.md: -------------------------------------------------------------------------------- 1 | # HTTP 2 | 3 | ## 一、HTTP 协议工作原理 4 | 5 | ## 二、URL Loading System 6 | 7 | ### 支持的协议 8 | - ftp:// 9 | - http:// 10 | - https:// 11 | - file:// 12 | - data:// 13 | 14 | ## 三、NSURLSession 15 | 16 | 如何管理 NSURLSession 对象? 17 | 18 | ## 参考资料 19 | 20 | ### 官方文档 21 | - [URL Session Programming Guide](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/URLLoadingSystem/URLLoadingSystem.html) Updated 2016-09-13 22 | 23 | ### 文章 24 | - [NSURLSession Tutorial: Getting Started](https://www.raywenderlich.com/110458/nsurlsession-tutorial-getting-started) by raywenderlich 2016 25 | - HTTPS从原理到应用 by 简书 TIME_for 2016 26 | - [HTTPS从原理到应用(一):加密(Encrypt)与哈希(Hash)](http://www.jianshu.com/p/2542c95fb023) 27 | - [HTTPS从原理到应用(二):数字证书(Digital Certificate)与数字签名(Digital Signature)](http://www.jianshu.com/p/e767a4e9252e) 28 | - [HTTPS从原理到应用(三):SSL/TLS协议](http://www.jianshu.com/p/c93612b3abac) 29 | - [HTTPS从原理到应用(四):iOS中HTTPS实际使用](http://www.jianshu.com/p/ce2a9bc519f5) 30 | - [iOS对HTTPS证书链的验证](http://www.jianshu.com/p/74830162717e) by 简书 XcodeMen 2016 31 | - [译] URL加载系统 by 南峰子 2014(注:官方文档已更新) 32 | - [URL加载系统之一:基本结构](http://southpeak.github.io/2014/07/11/url-load-system-1/) 33 | - [URL加载系统之二:NSURLSession](http://southpeak.github.io/2014/07/11/url-load-system-2/) 34 | - [URL加载系统之三:NSURLConnection](http://southpeak.github.io/2014/07/15/url-load-system-3/) 35 | - [URL加载系统之四:认证与TLS链验证](http://southpeak.github.io/2014/07/16/url-load-system-4/) 36 | - [URL加载系统之五:缓存、Cookies与协议](http://southpeak.github.io/2014/07/16/url-load-system-5/) 37 | 38 | ### 轮子 39 | - [AFNetworking](https://github.com/AFNetworking/AFNetworking) 40 | - [YTKNetwork](https://github.com/yuantiku/YTKNetwork) 41 | - [CTNetworking](https://github.com/casatwy/RTNetworking) 42 | - [CPNetworking](https://github.com/crespoxiao/CPNetworking) 43 | - [XMNetworking](https://github.com/kangzubin/XMNetworking) 44 | - [SDWebImage](https://github.com/rs/SDWebImage) 45 | - [YYWebImage](https://github.com/ibireme/YYWebImage) 46 | - [OHHTTPStubs](https://github.com/AliSoftware/OHHTTPStubs) 47 | - [Alamofire](https://github.com/Alamofire/Alamofire) - Swift 版 AFNetworking 48 | - [Kingfisher](https://github.com/onevcat/Kingfisher) - Swfit 版 SDWebImage 49 | - [XMPPFramework](https://github.com/robbiehanson/XMPPFramework) 50 | - [CocoaAsyncSocket](https://github.com/robbiehanson/CocoaAsyncSocket) 51 | -------------------------------------------------------------------------------- /网络/HTTP/URL_Session_Programming_Guide_zh.md: -------------------------------------------------------------------------------- 1 | # [译] URL Session Programming Guide 2 | 3 | 参考译文: [URL加载系统 ](http://southpeak.github.io/2014/07/11/url-load-system-1/) by 南峰子 2014 4 | 5 | 目录 6 | 7 | 8 | - [1. 关于 URL 加载系统](#1-关于-url-加载系统) 9 | - [1.1. 初见](#11-初见) 10 | - [URL 加载](#url-加载) 11 | - [辅助类](#辅助类) 12 | - [重定向](#重定向) 13 | - [认证与证书](#认证与证书) 14 | - [Cache Management](#cache-management) 15 | - [Cookie 存储](#cookie-存储) 16 | - [Protocol Support](#protocol-support) 17 | - [1.2. 如何使用该文档](#12-如何使用该文档) 18 | - [2. 使用 NSURLSession](#2-使用-nsurlsession) 19 | - [2.1. 理解 URL Session 的概念](#21-理解-url-session-的概念) 20 | - [会话类型](#会话类型) 21 | - [任务类型](#任务类型) 22 | - [后台传输注意事项](#后台传输注意事项) 23 | - [2.2. 创建并配置会话](#22-创建并配置会话) 24 | - [3. 编码与解码 URL 数据](#3-编码与解码-url-数据) 25 | - [4. 重定向与其他请求变更](#4-重定向与其他请求变更) 26 | - [5. 认证与 TLS 链验证](#5-认证与-tls-链验证) 27 | - [5.1. 决定如何响应一个认证请求](#51-决定如何响应一个认证请求) 28 | - [6. 理解缓存](#6-理解缓存) 29 | - [7. Cookie 与自定义协议](#7-cookie-与自定义协议) 30 | - [8. URL Session 生命周期](#8-url-session-生命周期) 31 | 32 | 33 | 34 | ## 1. 关于 URL 加载系统 35 | 36 | 这篇指南描述一些 Foundation 框架中的类。这些类与 URL 相关并可以通过标准的 Internet 协议与服务端进行通信。这些类通常被统称为 URL 加载系统。 37 | 38 | URL 加载系统是类与协议的集合。这些类帮助我们可以通过 URL 访问内容。`NSURL` 类处于核心地位,通过它我们可以操作 URL 和其指向的资源。 39 | 40 | 我们可以使用 `Foundation` 提供的类加载 URL 的内容、上传数据至服务端、管理 cookie 存储、控制响应缓存、处理证书存储和认证、实现自定义协议扩展。 41 | 42 | URL 加载系统支持通过以下协议访问资源: 43 | - File Transfer Protocol (ftp://) 44 | - Hypertext Transfer Protocol (http://) 45 | - Hypertext Transfer Protocol with encryption (https://) 46 | - Local file URLs (file:///) 47 | - Data URLs (data://) 48 | 49 | 还支持代理服务和 SOCKS 网关。 50 | 51 | > Important: On Apple platforms, a networking security feature called App Transport Security (ATS) is available to apps and app extensions, and is enabled by default. It improves privacy and data integrity by ensuring your app’s network connections employ only industry-standard protocols and ciphers without known weaknesses. 52 | For more information, see NSAppTransportSecurity. 53 | 54 | > Note: In addition to the URL loading system, OS X and iOS provide APIs for opening URLs in other applications, such as Safari. These APIs are not described in this document. 55 | For more information about Launch Services in OS X, read Launch Services Programming Guide. 56 | For more information about the openURL: method in the NSWorkSpace class in OS X, read NSWorkspace Class Reference. 57 | For more information about the openURL: method in the UIApplication class in iOS, read UIApplication Class Reference. 58 | 59 | ### 1.1. 初见 60 | The URL loading system includes classes that load URLs along with a number of important helper classes that work with those URL loading classes to modify their behavior. The major helper classes fall into five categories: protocol support, authentication and credentials, cookie storage, configuration management, and cache management. 61 | 62 | ![image](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/URLLoadingSystem/Art/nsobject_hierarchy_2x.png) 63 | 64 | #### URL 加载 65 | URL 加载系统中最常用的类允许我们通过 URL 从源获取内容。我们可以使用 `NSURLSession` 获取内容。你应该使用哪个方法很大程度上取决于是要将数据保存到内存还是下载到磁盘。 66 | 67 | 有两种方式从 URL 获取数据: 68 | - 对于简单的请求,使用 `NSURLSession` API直接从 `NSURL` 对象获取数据,数据可以是 `NSData` 对象也可以是一个在磁盘上的文件。 69 | - 对于更复杂的请求(比如上传数据)需要提供一个 `NSURLRequest` 或 `NSMutableURLRequest` 对象给 `NSURLSession`。 70 | 71 | 无论你选择哪种方式,我们都有两种方式来获得响应数据: 72 | - block 73 | - delegate 74 | 75 | 除了数据本身,响应对象还封装了与请求相关的元数据,比如 MIME 类型和内容长度。 76 | 77 | > 注:通过 `NSURLSession` 下载不会有缓存。如果需要缓存,我们必须自己将数据写入磁盘。 78 | 79 | #### 辅助类 80 | 81 | 82 | #### 重定向 83 | 一些协议,比如 HTTP,允许服务端告知我们访问的内容已经被移到了另一个 URL。URL 加载类能够通过 delegate 通知我们。如果我们提供了合适的代理方法,我们可以决定是否要重定向,返回重定向后的响应结果还是返回错误。 84 | 85 | #### 认证与证书 86 | 一些服务器对某些内容的访问有限制,需要用户提供证书来通过认证并获得访问权限。 87 | 88 | #### Cache Management 89 | 90 | #### Cookie 存储 91 | 由于 HTTP 是一种无状态协议,客户端经常使用 cookies 来提供 URL 请求数据的持久存储。URL 加载系统提供了用来创建和管理 cookies、将 cookies 作为 HTTP 请求的一部分发出、从 Web 服务端响应中取出 cookies。OS X 和 iOS 提供 `NSHTTPCookieStorage` 类来管理 `NSHTTPCookie` 对象。在 OS X 中,cookie 存储被所用应用共享;而 iOS 中,cookie 存储是每个应用独立一份。 92 | 93 | #### Protocol Support 94 | 95 | ### 1.2. 如何使用该文档 96 | 首先阅读 [使用 NSURLSession](#2-使用-nsurlsession) 了解 URL 加载系统。然后阅读 [URL Session 生命周期](#8-url-session-生命周期) 来深入学习 `NSURLSession` 是如何与其 delegates 相互作用的。以下章节提供了关于 URL 加载系统其他方面的信息: 97 | - [编码与解码 URL 数据](#3-编码与解码-url-数据) 介绍如何对字符串进行编码使其能够安全的在 URL 中使用 98 | - [重定向与其他请求变更]() 介绍当你的请求发生变化时你能做什么 99 | - [认证与 TLS 链验证]() 介绍如何验证你与服务器之间的安全连接 100 | - [理解缓存]() 介绍在一次请求中如何使用缓存 101 | - [Cookie 与自定义协议]() 介绍可用于管理 Cookie 存储和自定义应用层协议的类 102 | 103 | ## 2. 使用 NSURLSession 104 | `NSURLSession` 及其相关类提供通过 HTTP 协议下载数据的 API。该 API 提供了丰富的代理方法来支持认证和后台下载(程序未运行或挂起时)。 105 | 106 | 使用 `NSURLSession` API,应用需要创建一系列的会话,每个会话负责协调一组相关数据的传输任务。比如你正在写一个 web 浏览器,我们需要为每个页签或者窗口创建一个会话。在每个会话中,添加一系列的任务,每个任务都表示一个对指定 URL 的请求。 107 | 108 | 与大多数网络 API 一样,`NSURLSession` API 是异步的。如果我们使用系统提供的代理,我们必须提供一个请求完成处理 block,以便在请求成功或失败时返回数据给我们的应用。如果我们提供自定义的代理对象,则任务对象调用这些代理方法,并回传从服务端获取的数据(如果是文件下载,则当传输完成时调用)。 109 | 110 | > 注:完成后回调(Completion callbacks)可以作为自定义 delegate 的一种替代方案。如果我们使用回调这种方式来创建任务,则 delegate 将不会被调用。 111 | 112 | `NSURLSession` API 提供了 status 和 progress 属性,并作为额外的信息传递给代理。同时它支持取消、重启(恢复)、挂起操作,并支持断点续传功能。 113 | 114 | ### 2.1. 理解 URL Session 的概念 115 | 会话(Session)中任务(Task)的行为取决于三点:会话的类型、任务的类型以及创建任务时应用是否处于前台。 116 | 117 | #### 会话类型 118 | `NSURLSession` 支持三种类型的会话(取决于创建会话时的配置对象) 119 | - 默认会话(Default sessions):行为与其它下载 URL 的 Foundation 方法类似。使用基于磁盘的缓存策略,并在用户 keychain 中存储证书。 120 | - 短暂会话(Ephemeral sessions):不存储任何数据在磁盘中;所有的缓存、证书存储等都保存在内存中并与会话绑定。这样,当应用结束会话时,它们被自动释放。 121 | - 后台会话(Background sessions):类似于默认会话,除了有一个独立的进程来处理所有的数据传输。 122 | 123 | #### 任务类型 124 | 一个会话中,`NSURLSession` 支持三种类型的任务 125 | - 数据任务(data tasks):使用 `NSData` 对象来发送和接收数据,数据可以分片返回,也可以完成后一次性返回。 126 | - 下载任务(download tasks):以文件的形式接收数据,支持后台下载。 127 | - 上传任务(upload tasks):以文件的形式发送数据,支持后台上传。 128 | 129 | #### 后台传输注意事项 130 | `NSURLSession` 支持在程序挂起时在后台传输数据。后台传输只由使用后台会话配置对象创建的会话提供(调用 `backgroundSessionConfiguration:`)。 131 | 132 | 使用后台会话时,由于实际传输是在一个独立的进程中传输,且重启应用进程相当损耗资源,只有少量特性可以使用,所以有以下限制: 133 | - 会话必须提供用于事件分发的代理 134 | - 只支持 HTTP 和 HTTPS 协议(不支持自定义协议) 135 | - 总是伴随着重定义操作 136 | - 仅支持从文件上传的任务(程序退出时从数据对象或者流上传的任务将失败) 137 | - 如果当应用在后台时初始化的后台传输,则配置对象的 discretionary 属性为 true 138 | 139 | > 注:iOS 8 和 OS X 10.10 以前,后台会话不支持数据任务。 140 | 141 | ### 2.2. 创建并配置会话 142 | `NSURLSession` 提供了丰富的配置选项: 143 | - 支持缓存、cookie、认证及协议的私有存储 144 | - 认证 145 | - 上传下载文件 146 | - 每个主机的连接的最大数 147 | - 超时时间 148 | - 支持的 TLS 最大和最小版本 149 | - 自定义代理字典 150 | - 控制 cookie 策略 151 | - 控制 HTTP 管道行为 152 | 153 | 由于大部分设置都包含在一个独立的配置对象中,所以我们可以重用这些配置。当我们初始化一个会话对象时,我们指定了如下内容: 154 | - 一个配置对象。用于管理会话和任务的行为 155 | - 一个代理对象(可选)。用于处理接收的数据及其它事件,如服务端认证、决定一个资源加载请求是否应该转换成下载等。 156 | 157 | 如果我们不提供一个代理对象,`NSURLSession` 将使用系统提供的代理。In this way, you can readily use NSURLSession in place of existing code that uses the sendAsynchronousRequest:queue:completionHandler: convenience method on NSURLSession.(译者注:未找到该方法) 158 | 159 | > 注:如果我们的应用需要执行后台传输,必须提供一个自定义的代理对象。 160 | 161 | 当实例化一个会话对象后,我们无法改变配置或者代理,除非创建新的会话。 162 | 163 | 示例程序 1-2 164 | ``` Objective-C 165 | // 创建会话配置 166 | NSURLSessionConfiguration *defaultConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; 167 | NSURLSessionConfiguration *ephemeralConfiguration = [NSURLSessionConfiguration ephemeralSessionConfiguration]; 168 | NSURLSessionConfiguration *backgroundConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier: @"com.myapp.networking.background"]; 169 | 170 | // 为默认会话配置缓存行为 171 | NSString *cachesDirectory = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject; 172 | NSString *cachePath = [cachesDirectory stringByAppendingPathComponent:@"MyCache"]; 173 | 174 | /* Note: 175 | iOS requires the cache path to be 176 | a path relative to the ~/Library/Caches directory, 177 | but OS X expects an absolute path. 178 | */ 179 | #if TARGET_OS_OSX 180 | cachePath = [cachePath stringByStandardizingPath]; 181 | #endif 182 | 183 | NSURLCache *cache = [[NSURLCache alloc] initWithMemoryCapacity:16384 diskCapacity:268435456 diskPath:cachePath]; 184 | defaultConfiguration.URLCache = cache; 185 | defaultConfiguration.requestCachePolicy = NSURLRequestUseProtocolCachePolicy; 186 | 187 | // 创建会话 188 | id delegate = [[MySessionDelegate alloc] init]; 189 | NSOperationQueue *operationQueue = [NSOperationQueue mainQueue]; 190 | 191 | NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration:defaultConfiguration delegate:delegate operationQueue:operationQueue]; 192 | NSURLSession *ephemeralSession = [NSURLSession sessionWithConfiguration:ephemeralConfiguration delegate:delegate delegateQueue:operationQueue]; 193 | NSURLSession *backgroundSession = [NSURLSession sessionWithConfiguration:backgroundConfiguration delegate:delegate delegateQueue:operationQueue]; 194 | ``` 195 | 196 | ## 3. 编码与解码 URL 数据 197 | 198 | ## 4. 重定向与其他请求变更 199 | 200 | ## 5. 认证与 TLS 链验证 201 | 一个 `NSURLRequest` 对象经常会遇到认证请求,或者需要从其所连接的服务端请求证书。当需要认证请求时,`NSURLSession` 会通知它们的代理对象,以便能正确地做处理。 202 | 203 | ### 5.1. 决定如何响应一个认证请求 204 | 205 | ## 6. 理解缓存 206 | 207 | ## 7. Cookie 与自定义协议 208 | 209 | ## 8. URL Session 生命周期 -------------------------------------------------------------------------------- /网络/README.md: -------------------------------------------------------------------------------- 1 | # 网络 2 | - [HTTP](HTTP) 3 | - [XMPP](XMPP) 4 | - RTP 5 | - [TCP](TCP) 6 | - UDP 7 | - TLS/SSL 8 | -------------------------------------------------------------------------------- /网络/TCP/README.md: -------------------------------------------------------------------------------- 1 | # TCP 2 | 3 | ## 参考资料 4 | 5 | ### 文章 6 | 0. [TCP 的那些事儿(上)](http://coolshell.cn/articles/11564.html) by 陈皓 CoolShell 7 | 0. [TCP 的那些事儿(下)](http://coolshell.cn/articles/11609.html) by 陈皓 CoolShell 8 | -------------------------------------------------------------------------------- /网络/XMPP/README.md: -------------------------------------------------------------------------------- 1 | # XMPP 2 | --------------------------------------------------------------------------------