update 2 new article
This commit is contained in:
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.1" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.1" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
@ -587,7 +587,7 @@
|
||||
|
||||
<div class="page-inner">
|
||||
|
||||
<section class="normal" id="section-gitbook_40">
|
||||
<section class="normal" id="section-gitbook_8">
|
||||
|
||||
<h1 id="-">基础部分</h1>
|
||||
<p>Swift 是 iOS 和 OS X 应用开发的一门新语言。然而,如果你有 C 或者 Objective-C 开发经验的话,你会发现 Swift 的很多内容都是你熟悉的。</p>
|
||||
@ -978,7 +978,7 @@ assert(age >= 0, "A person's age cannot be less than zero")
|
||||
<a href="../chapter2/chapter2.html" class="navigation navigation-prev " aria-label="Previous page: Swift 教程"><i class="fa fa-angle-left"></i></a>
|
||||
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" class="navigation navigation-next " aria-label="Next page: 基本操作符"><i class="fa fa-angle-right"></i></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" class="navigation navigation-next " aria-label="Next page: 基本运算符"><i class="fa fa-angle-right"></i></a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
|
||||
<meta charset="UTF-8">
|
||||
<title>基本操作符 | Swift 编程语言</title>
|
||||
<title>基本运算符 | Swift 编程语言</title>
|
||||
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<meta name="robots" content="index, follow">
|
||||
@ -21,7 +21,7 @@
|
||||
<link rel="prev" href="../chapter2/01_The_Basics.html" />
|
||||
|
||||
|
||||
<meta property="og:title" content="基本操作符 | Swift 编程语言">
|
||||
<meta property="og:title" content="基本运算符 | Swift 编程语言">
|
||||
<meta property="og:site_name" content="Swift 编程语言">
|
||||
<meta property="og:type" content="book">
|
||||
<meta property="og:locale" content="en_US">
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.2" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.2" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter done " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
@ -587,7 +587,7 @@
|
||||
|
||||
<div class="page-inner">
|
||||
|
||||
<section class="normal" id="section-gitbook_62">
|
||||
<section class="normal" id="section-gitbook_30">
|
||||
|
||||
<h1 id="-">基础运算符</h1>
|
||||
<p>运算符是检查, 改变, 合并值的特殊符号或短语. 例如, 加号 <code>+</code> 把计算两个数的和(如 <code>let i = 1 + 2</code>). 复杂些的运行算包括逻辑与<code>&&</code>(如 <code>if enteredDoorCode && passedRetinaScan</code>), 还有自增运算符 <code>++i</code> 这样让自身加一的便捷运算.</p>
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.3" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.3" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter done " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
@ -587,7 +587,7 @@
|
||||
|
||||
<div class="page-inner">
|
||||
|
||||
<section class="normal" id="section-gitbook_41">
|
||||
<section class="normal" id="section-gitbook_9">
|
||||
|
||||
<h1 id="-strings-and-characters-">字符串和字符 (Strings and Characters)</h1>
|
||||
<p>本页包含内容:</p>
|
||||
@ -877,7 +877,7 @@ print("\n")
|
||||
</div>
|
||||
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" class="navigation navigation-prev " aria-label="Previous page: 基本操作符"><i class="fa fa-angle-left"></i></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" class="navigation navigation-prev " aria-label="Previous page: 基本运算符"><i class="fa fa-angle-left"></i></a>
|
||||
|
||||
|
||||
<a href="../chapter2/04_Collection_Types.html" class="navigation navigation-next " aria-label="Next page: 集合类型"><i class="fa fa-angle-right"></i></a>
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.4" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.4" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter done " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.5" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.5" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter done " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.6" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.6" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter done " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
@ -587,7 +587,7 @@
|
||||
|
||||
<div class="page-inner">
|
||||
|
||||
<section class="normal" id="section-gitbook_55">
|
||||
<section class="normal" id="section-gitbook_23">
|
||||
|
||||
<h1 id="-functions-">函数(Functions)</h1>
|
||||
<p>本页包含内容:</p>
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.7" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.7" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter done " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
@ -587,7 +587,7 @@
|
||||
|
||||
<div class="page-inner">
|
||||
|
||||
<section class="normal" id="section-gitbook_56">
|
||||
<section class="normal" id="section-gitbook_24">
|
||||
|
||||
<h1 id="-">闭包</h1>
|
||||
<p>本页内容包含:</p>
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.8" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.8" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter done " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
@ -587,7 +587,7 @@
|
||||
|
||||
<div class="page-inner">
|
||||
|
||||
<section class="normal" id="section-gitbook_57">
|
||||
<section class="normal" id="section-gitbook_25">
|
||||
|
||||
<h1 id="-">枚举</h1>
|
||||
<p>本页内容包含:</p>
|
||||
@ -628,7 +628,7 @@
|
||||
</code></pre><p><code>directionToHead</code>的类型被推断当它被<code>CompassPoint</code>的一个可能值初始化。一旦<code>directionToHead</code>被声明为一个<code>CompassPoint</code>,你可以使用更短的点(.)语法将其设置为另一个<code>CompassPoint</code>的值:</p>
|
||||
<pre><code>directionToHead = .East
|
||||
</code></pre><p><code>directionToHead</code>的类型已知时,当设定它的值时,你可以不再写类型名。使用显示类型的枚举值可以让代码具有更好的可读性。</p>
|
||||
<h2 id="-switch-">用<code>Switch</code>语句匹配枚举值</h2>
|
||||
<h2 id="-switch-">匹配枚举值和<code>Switch</code>语句</h2>
|
||||
<p>你可以匹配单个枚举值和<code>switch</code>语句:</p>
|
||||
<pre><code>directionToHead = .South
|
||||
switch directionToHead {
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.9" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.9" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter done " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
@ -587,7 +587,7 @@
|
||||
|
||||
<div class="page-inner">
|
||||
|
||||
<section class="normal" id="section-gitbook_58">
|
||||
<section class="normal" id="section-gitbook_26">
|
||||
|
||||
<h3 id="-">类和结构体</h3>
|
||||
<p>本页包含内容:</p>
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.10" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.10" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.11" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.11" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
@ -587,7 +587,7 @@
|
||||
|
||||
<div class="page-inner">
|
||||
|
||||
<section class="normal" id="section-gitbook_60">
|
||||
<section class="normal" id="section-gitbook_28">
|
||||
|
||||
<h1 id="-methods-">方法(Methods)</h1>
|
||||
<p><strong>方法</strong>是与某些特定类型相关联的功能/函数。类、结构体、枚举都可以定义实例方法;实例方法为指定类型的实例封装了特定的任务与功能。类、结构体、枚举也可以定义类(型)方法(type itself);类型方法与类型自身相关联。类型方法与Objective-C中的类方法(class methods)相似。</p>
|
||||
@ -798,7 +798,7 @@ println("level 6 has not yet been unlocked")
|
||||
<a href="../chapter2/10_Properties.html" class="navigation navigation-prev " aria-label="Previous page: 属性"><i class="fa fa-angle-left"></i></a>
|
||||
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" class="navigation navigation-next " aria-label="Next page: 下标"><i class="fa fa-angle-right"></i></a>
|
||||
<a href="../chapter2/12_Subscripts.html" class="navigation navigation-next " aria-label="Next page: 附属脚本"><i class="fa fa-angle-right"></i></a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
|
||||
<meta charset="UTF-8">
|
||||
<title>下标 | Swift 编程语言</title>
|
||||
<title>附属脚本 | Swift 编程语言</title>
|
||||
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<meta name="robots" content="index, follow">
|
||||
@ -21,7 +21,7 @@
|
||||
<link rel="prev" href="../chapter2/11_Methods.html" />
|
||||
|
||||
|
||||
<meta property="og:title" content="下标 | Swift 编程语言">
|
||||
<meta property="og:title" content="附属脚本 | Swift 编程语言">
|
||||
<meta property="og:site_name" content="Swift 编程语言">
|
||||
<meta property="og:type" content="book">
|
||||
<meta property="og:locale" content="en_US">
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.12" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.12" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
@ -587,7 +587,7 @@
|
||||
|
||||
<div class="page-inner">
|
||||
|
||||
<section class="normal" id="section-gitbook_61">
|
||||
<section class="normal" id="section-gitbook_29">
|
||||
|
||||
<h1 id="-subscripts-">下标 (Subscripts)</h1>
|
||||
<p>下标可以定义在类(Class)、结构体(structures)和枚举(enumerations)这些目标中,可以认为是访问对象、集合或序列的快捷方式。举例来说,用下标访问一个数组(Array)实例中的元素可以这样写 <code>someArray[index]</code> ,访问字典(Dictionary)实例中的元素可以这样写 <code>someDictionary[key]</code>,而不需要再调用实例的某个方法来获得元素的值。</p>
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.13" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.13" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
@ -587,7 +587,7 @@
|
||||
|
||||
<div class="page-inner">
|
||||
|
||||
<section class="normal" id="section-gitbook_39">
|
||||
<section class="normal" id="section-gitbook_7">
|
||||
|
||||
<h1 id="-">继承</h1>
|
||||
<p>一个类可以继承另一个类的方法,属性和其它特性。当一个类继承其它类,继承类叫子类,被继承类叫超类(或父类)。在Swift中,继承是区分「类」与其它类型的一个基本特征。</p>
|
||||
@ -755,7 +755,7 @@ println("AutomaticCar: \(automatic.description())")
|
||||
</div>
|
||||
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" class="navigation navigation-prev " aria-label="Previous page: 下标"><i class="fa fa-angle-left"></i></a>
|
||||
<a href="../chapter2/12_Subscripts.html" class="navigation navigation-prev " aria-label="Previous page: 附属脚本"><i class="fa fa-angle-left"></i></a>
|
||||
|
||||
|
||||
<a href="../chapter2/14_Initialization.html" class="navigation navigation-next " aria-label="Next page: 构造过程"><i class="fa fa-angle-right"></i></a>
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.14" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.14" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.15" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.15" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
@ -587,7 +587,7 @@
|
||||
|
||||
<div class="page-inner">
|
||||
|
||||
<section class="normal" id="section-gitbook_64">
|
||||
<section class="normal" id="section-gitbook_32">
|
||||
|
||||
<h1 id="-">析构过程</h1>
|
||||
<p>在一个类的实例被释放之前,析构函数被立即调用。用关键字deinit来标示析构函数,类似于初始化函数用init来标示。析构函数只适用于类类型。</p>
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.16" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.16" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
@ -587,7 +587,7 @@
|
||||
|
||||
<div class="page-inner">
|
||||
|
||||
<section class="normal" id="section-gitbook_65">
|
||||
<section class="normal" id="section-gitbook_33">
|
||||
|
||||
<h1 id="-">自动引用计数</h1>
|
||||
<p>本页包含内容:</p>
|
||||
@ -607,10 +607,320 @@
|
||||
<h2 id="-">自动引用计数的工作机制</h2>
|
||||
<p>当你每次创建一个类的新的实例的时候,ARC会分配一大块内存用来储存实例的信息。内存中会包含实例的类型信息,以及这个实例所有相关属性的值。此外,当实例不再被使用时,ARC释放实例所占用的内存,并让释放的内存能挪作他用。这确保了不再被使用的实例,不会一直占用内存空间。</p>
|
||||
<p>然而,当ARC收回和释放了正在被使用中的实例,该实例的属性和方法将不能再被访问和调用。实际上,如果你试图访问这个实例,你的应用程序很可能会崩溃。</p>
|
||||
<p>为了确保使用中的实例不会被回收,ARC会跟踪和计算每一个类实例正在被多少属性,常量和变量所引用。哪怕实例的引用数为一,ARC都不会回收这个实例。</p>
|
||||
<p>为了使之成为可能,无论你将类实例赋值给属性,常量或者是变量,属性,常量或者变量,都会对此实例创建强引用。之所以称之为强引用,是因为它会将实例牢牢的保持住,只要强引用还在,实例是不允许被释放的。</p>
|
||||
<h2 id="-">自动引用计数实践</h2>
|
||||
<p>为了确保使用中的实例不会被销毁,ARC会跟踪和计算每一个实例正在被多少属性,常量和变量所引用。哪怕实例的引用数为一,ARC都不会销毁这个实例。</p>
|
||||
<p>为了使之成为可能,无论你将实例赋值给属性,常量或者是变量,属性,常量或者变量,都会对此实例创建强引用。之所以称之为强引用,是因为它会将实例牢牢的保持住,只要强引用还在,实例是不允许被销毁的。</p>
|
||||
<h2 id="-">自动引用计数实战</h2>
|
||||
<p>下面的例子展示了自动引用计数的工作机制。例子以一个简单的Person类开始,并定义了一个叫name的常量属性:</p>
|
||||
<pre><code> class Person {
|
||||
let name: String
|
||||
|
||||
init(name: String) {
|
||||
self.name = name
|
||||
println("\(name) is being initialized")
|
||||
}
|
||||
|
||||
deinit {
|
||||
println("\(name) is being deinitialized")
|
||||
}
|
||||
}
|
||||
</code></pre><p>Person类有一个构造函数,此构造函数为实例的name属性赋值并打印出信息,以表明初始化过程生效。Person类同时也拥有析构函数,同样会在实例被销毁的时候打印出信息。</p>
|
||||
<p>接下来的代码片段定义了三个类型为Person?的变量,用来按照代码片段中的顺序,为新的Person实例建立多个引用。由于这些变量是被定义为可选类型(Person?,而不是Person),它们的值会被自动初始化为nil,目前还不会引用到Person类的实例。</p>
|
||||
<pre><code> var reference1: Person?
|
||||
var reference2: Person?
|
||||
var reference3: Person?
|
||||
</code></pre><p>现在你可以创建Person类的新实例,并且将它赋值给三个变量其中的一个:</p>
|
||||
<pre><code> reference1 = Person(name: "John Appleseed")
|
||||
// prints "John Appleseed is being initialized”
|
||||
</code></pre><p>应当注意到当你调用Person类的构造函数的时候,"John Appleseed is being initialized”会被打印出来。由此可以确定构造函数被执行。</p>
|
||||
<p>由于Person类的新实例被赋值给了reference1变量,所以reference1到Person类的新实例之间建立了一个强引用。正是因为这个强引用,ARC会保证Person实例被保持在内存中不被销毁。</p>
|
||||
<p>如果你将同样的Person实例也赋值给其他两个变量,该实例又会多出两个强引用:</p>
|
||||
<pre><code> reference2 = reference1
|
||||
reference3 = reference1
|
||||
</code></pre><p>现在这个Person实例已经有三个强引用了。</p>
|
||||
<p>如果你通过给两个变量赋值nil的方式断开两个强引用(包括最先的那个强引用),只留下一个强引用,Person实例不会被销毁:</p>
|
||||
<pre><code>reference2 = reference1
|
||||
reference3 = reference1
|
||||
</code></pre><p>ARC会在第三个,也即最后一个强引用被断开的时候,销毁Person实例,这也意味着你不再使用这个Person实例:</p>
|
||||
<pre><code>reference3 = nil
|
||||
// prints "John Appleseed is being deinitialized"
|
||||
</code></pre><h2 id="-">类实例之间的循环强引用</h2>
|
||||
<p>在上面的例子中,ARC会跟踪你所新创建的Person实例的引用数量,并且会在Person实例不再被需要时销毁它。</p>
|
||||
<p>然而,我们可能会写出这样的代码,一个类永远不会有0个强引用。这种情况发生在两个类实例互相保持对方的强引用,并让对方不被销毁。这就是所谓的循环强引用。</p>
|
||||
<p>你可以通过定义类之间的关系为弱引用或者无主引用,以此替代强引用,从而解决循环强引用的问题。具体的过程在<a href="http://numbbbbb.github.io/the-swift-programming-language-in-chinese/chapter2/16_Automatic_Reference_Counting.html#1" target="_blank">解决类实例之间的循环强引用</a>中有描述。不管怎样,在你学习怎样解决循环强引用之前,很有必要了解一下它是怎样产生的。</p>
|
||||
<p>下面展示了一个不经意产生循环强引用的例子。例子定义了两个类:Person和Apartment,用来建模公寓和它其中的居民:</p>
|
||||
<pre><code>class Person {
|
||||
let name: String
|
||||
init(name: String) { self.name = name }
|
||||
var apartment: Apartment?
|
||||
deinit { println("\(name) is being deinitialized") }
|
||||
}
|
||||
|
||||
class Apartment {
|
||||
let number: Int
|
||||
init(number: Int) { self.number = number }
|
||||
var tenant: Person?
|
||||
deinit { println("Apartment #\(number) is being deinitialized") }
|
||||
}
|
||||
</code></pre><p>每一个Person实例有一个类型为String,名字为name的属性,并有一个可选的初始化为nil的apartment属性。apartment属性是可选的,因为一个人并不总是拥有公寓。</p>
|
||||
<p>类似的,每个Apartment实例有一个叫number,类型为Int的属性,并有一个可选的初始化为nil的tenant属性。tenant属性是可选的,因为一栋公寓并不总是有居民。</p>
|
||||
<p>这两个类都定义了析构函数,用以在类实例被析构的时候输出信息。这让你能够知晓Person和Apartment的实例是否像预期的那样被销毁。</p>
|
||||
<p>接下来的代码片段定义了两个可选类型的变量john和number73,并分别被设定为下面的Apartment和Person的实例。这两个变量都被初始化为nil,并为可选的:</p>
|
||||
<pre><code>var john: Person?
|
||||
var number73: Apartment?
|
||||
</code></pre><p>现在你可以创建特定的Person和Apartment实例并将类实例赋值给john和number73变量:</p>
|
||||
<pre><code>john = Person(name: "John Appleseed")
|
||||
number73 = Apartment(number: 73)
|
||||
</code></pre><p>在两个实例被创建和赋值后,下图表面了强引用的关系。变量john现在有一个指向Person实例的强引用,而变量number73有一个指向Apartment实例的强引用:</p>
|
||||
<p><img src="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Art/referenceCycle01_2x.png" alt=""></p>
|
||||
<p>现在你能够将这两个实例关联在一起,这样人就能有公寓住了,而公寓也有了房客。注意感叹号是用来展开和访问可选变量john和number73中的实例,这样实例的属性才能被赋值:</p>
|
||||
<pre><code>john!.apartment = number73
|
||||
number73!.tenant = john
|
||||
</code></pre><p>在将两个实例联系在一起之后,强引用的关系如图所示:</p>
|
||||
<p><img src="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Art/referenceCycle02_2x.png" alt=""></p>
|
||||
<p>不幸的是,将这两个实例关联在一起之后,一个循环强引用被创建了。Person实例现在有了一个指向Apartment实例的强引用,而Apartment实例也有了一个指向Person实例的强引用。因此,当你断开john和number73变量所持有的强引用时,引用计数并不会降为0,实例也不会被ARC销毁:</p>
|
||||
<pre><code>john = nil
|
||||
number73 = nil
|
||||
</code></pre><p>注意,当你把这两个变量设为nil时,没有任何一个析构函数被调用。强引用循环阻止了Person和Apartment类实例的销毁,并在你的应用程序中造成了内存泄漏。</p>
|
||||
<p>在你将john和number73赋值为nil后,强引用关系如下图:</p>
|
||||
<p><img src="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Art/referenceCycle03_2x.png" alt=""></p>
|
||||
<p>Person和Apartment实例之间的强引用关系保留了下来并且不会被断开。</p>
|
||||
<h2 id="-">解决实例之间的循环强引用</h2>
|
||||
<p>Swift提供了两种办法用来解决你在使用类的属性时所遇到的循环强引用问题:弱引用(weak reference)和无主引用(unowned reference)。</p>
|
||||
<p>弱引用和无主引用允许循环引用中的一个实例引用另外一个实例而不保持强引用。这样实例能够互相引用而不产生循环强引用。</p>
|
||||
<p>对于生命周期中会变为nil的实例使用弱引用。相反的,对于初始化赋值后再也不会被赋值为nil的实例,使用无主引用。</p>
|
||||
<h2 id="-">弱引用</h2>
|
||||
<p>弱引用不会牢牢保持住引用的实例,并且不会阻止ARC销毁被引用的实例。这种行为阻止了引用变为循环强引用。声明属性或者变量时,在前面加上weak关键字表明这是一个弱引用。</p>
|
||||
<p>在实例的生命周期中,如果某些时候引用没有值,那么弱引用可以阻止循环强引用。如果引用总是有值,则可以使用无主引用,在<a href="http://numbbbbb.github.io/the-swift-programming-language-in-chinese/chapter2/16_Automatic_Reference_Counting.html#2" target="_blank">无主引用</a>中有描述。在上面Apartment的例子中,一个公寓的生命周期中,有时是没有“居民”的,因此适合使用弱引用来解决循环强引用。</p>
|
||||
<blockquote>
|
||||
<p>注意: 弱引用必须被声明为变量,表明其值能在运行时被修改。弱引用不能被声明为常量。</p>
|
||||
</blockquote>
|
||||
<p>因为弱引用可以没有值,你必须将每一个弱引用声明为可选类型。可选类型是在Swift语言中推荐的用来表示可能没有值的类型。</p>
|
||||
<p>因为弱引用不会保持所引用的实例,即使引用存在,实例也有可能被销毁。因此,ARC会在引用的实例被销毁后自动将其赋值为nil。你可以像其他可选值一样,检查弱引用的值是否存在,你永远也不会遇到被销毁了而不存在的实例。</p>
|
||||
<p>下面的例子跟上面Person和Apartment的例子一致,但是有一个重要的区别。这一次,Apartment的tenant属性被声明为弱引用:</p>
|
||||
<pre><code>class Person {
|
||||
let name: String
|
||||
init(name: String) { self.name = name }
|
||||
var apartment: Apartment?
|
||||
deinit { println("\(name) is being deinitialized") }
|
||||
}
|
||||
|
||||
class Apartment {
|
||||
let number: Int
|
||||
init(number: Int) { self.number = number }
|
||||
weak var tenant: Person?
|
||||
deinit { println("Apartment #\(number) is being deinitialized") }
|
||||
}
|
||||
</code></pre><p>然后跟之前一样,建立两个变量(john和number73)之间的强引用,并关联两个实例:</p>
|
||||
<pre><code>var john: Person?
|
||||
var number73: Apartment?
|
||||
|
||||
john = Person(name: "John Appleseed")
|
||||
number73 = Apartment(number: 73)
|
||||
|
||||
john!.apartment = number73
|
||||
number73!.tenant = john
|
||||
</code></pre><p>现在,两个关联在一起的实例的引用关系如下图所示:</p>
|
||||
<p><img src="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Art/weakReference01_2x.png" alt=""></p>
|
||||
<p>Person实例依然保持对Apartment实例的强引用,但是Apartment实例只是对Person实例的弱引用。这意味着当你断开john变量所保持的强引用时,再也没有指向Person实例的强引用了:</p>
|
||||
<p><img src="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Art/weakReference02_2x.png" alt=""></p>
|
||||
<p>由于再也没有指向Person实例的强引用,该实例会被销毁:</p>
|
||||
<pre><code>john = nil
|
||||
// prints "John Appleseed is being deinitialized"
|
||||
</code></pre><p>唯一剩下的指向Apartment实例的强引用来自于变量number73。如果你断开这个强引用,再也没有指向Apartment实例的强引用了:</p>
|
||||
<p><img src="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Art/weakReference03_2x.png" alt=""></p>
|
||||
<p>由于再也没有指向Apartment实例的强引用,该实例也会被销毁:</p>
|
||||
<pre><code>number73 = nil
|
||||
// prints "Apartment #73 is being deinitialized"
|
||||
</code></pre><p>上面的两段代码展示了变量john和number73在被赋值为nil后,Person实例和Apartment实例的析构函数都打印出“销毁”的信息。这证明了引用循环被打破了。</p>
|
||||
<h2 id="-">无主引用</h2>
|
||||
<p>和弱引用类似,无主引用不会牢牢保持住引用的实例。和弱引用不同的是,无主引用是永远有值的。因此,无主引用总是被定义为非可选类型(non-optional type)。你可以在声明属性或者变量时,在前面加上关键字unowned表示这是一个无主引用。</p>
|
||||
<p>由于无主引用是非可选类型,你不需要在使用它的时候将它展开。无主引用总是可以被直接访问。不过ARC无法在实例被销毁后将无主引用设为nil,因为非可选类型的变量不允许被赋值为nil。</p>
|
||||
<blockquote>
|
||||
<p>注意: 如果你试图在实例被销毁后,访问该实例的无主引用,会触发运行时错误。使用无主引用,你必须确保引用始终指向一个未销毁的实例。</p>
|
||||
<p>还需要注意的是如果你试图访问实例已经被销毁的无主引用,程序会直接崩溃,而不会发生无法预期的行为。所以你应当避免这样的事情发生。</p>
|
||||
</blockquote>
|
||||
<p>下面的例子定义了两个类,Customer和CreditCard,模拟了银行客户和客户的信用卡。这两个类中,每一个都将另外一个类的实例作为自身的属性。这种关系会潜在的创造循环强引用。</p>
|
||||
<p>Customer和CreditCard之间的关系与前面弱引用例子中Apartment和Person的关系截然不同。在这个数据模型中,一个客户可能有或者没有信用卡,但是一张信用卡总是关联着一个客户。为了表示这种关系,Customer类有一个可选类型的card属性,但是CreditCard类有一个非可选类型的customer属性。</p>
|
||||
<p>此外,只能通过将一个number值和customer实例传递给CreditCard构造函数的方式来创建CreditCard实例。这样可以确保当创建CreditCard实例时总是有一个customer实例与之关联。</p>
|
||||
<p>由于信用卡总是关联着一个客户,因此将customer属性定义为无主引用,用以避免循环强引用:</p>
|
||||
<pre><code>class Customer {
|
||||
let name: String
|
||||
var card: CreditCard?
|
||||
init(name: String) {
|
||||
self.name = name
|
||||
}
|
||||
deinit { println("\(name) is being deinitialized") }
|
||||
}
|
||||
|
||||
class CreditCard {
|
||||
let number: Int
|
||||
unowned let customer: Customer
|
||||
init(number: Int, customer: Customer) {
|
||||
self.number = number
|
||||
self.customer = customer
|
||||
}
|
||||
deinit { println("Card #\(number) is being deinitialized") }
|
||||
}
|
||||
</code></pre><p>下面的代码片段定义了一个叫john的可选类型Customer变量,用来保存某个特定客户的引用。由于是可选类型,所以变量被初始化为nil。</p>
|
||||
<pre><code>var john: Customer?
|
||||
</code></pre><p>现在你可以创建Customer类的实例,用它初始化CreditCard实例,并将新创建的CreditCard实例赋值为客户的card属性。</p>
|
||||
<pre><code>john = Customer(name: "John Appleseed")
|
||||
john!.card = CreditCard(number: 1234_5678_9012_3456, customer: john!)
|
||||
</code></pre><p>在你关联两个实例后,他们的引用关系如下图所示:</p>
|
||||
<p><img src="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Art/unownedReference01_2x.png" alt=""></p>
|
||||
<p>Customer实例持有对CreditCard实例的强引用,而CreditCard实例持有对Customer实例的无主引用。</p>
|
||||
<p>由于customer的无主引用,当你断开john变量持有的强引用时,再也没有指向Customer实例的强引用了:</p>
|
||||
<p><img src="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Art/unownedReference02_2x.png" alt=""></p>
|
||||
<p>由于再也没有指向Customer实例的强引用,该实例被销毁了。其后,再也没有指向CreditCard实例的强引用,该实例也随之被销毁了:</p>
|
||||
<pre><code>john = nil
|
||||
// prints "John Appleseed is being deinitialized"
|
||||
// prints "Card #1234567890123456 is being deinitialized"
|
||||
</code></pre><p>最后的代码展示了在john变量被设为nil后Customer实例和CreditCard实例的构造函数都打印出了“销毁”的信息。</p>
|
||||
<h2 id="-">无主引用以及显式展开的可选属性</h2>
|
||||
<p>上面弱引用和无主引用的例子涵盖了两种常用的需要打破循环强引用的场景。</p>
|
||||
<p>Person和Apartment的例子展示了两个属性的值都允许为nil,并会潜在的产生循环强引用。这种场景最适合用弱引用来解决。</p>
|
||||
<p>Customer和CreditCard的例子展示了一个属性的值允许为nil,而另一个属性的值不允许为nil,并会潜在的产生循环强引用。这种场景最适合通过无主引用来解决。</p>
|
||||
<p>然而,存在着第三种场景,在这种场景中,两个属性都必须有值,并且初始化完成后不能为nil。在这种场景中,需要一个类使用无主属性,而另外一个类使用显示展开的可选属性。</p>
|
||||
<p>这使两个属性在初始化完成后能被直接访问(不需要可选展开),同事避免了循环引用。这一节将为你展示如何建立这种关系。</p>
|
||||
<p>下面的例子定义了两个类,Country和City,每个类将另外一个类的实例保存为属性。在这个模型中,每个国家必须有首都,而每一个城市必须属于一个国家。为了实现这种关系,Country类拥有一个capitalCity属性,而City类有一个country属性:</p>
|
||||
<pre><code>class Country {
|
||||
let name: String
|
||||
let capitalCity: City!
|
||||
init(name: String, capitalName: String) {
|
||||
self.name = name
|
||||
self.capitalCity = City(name: capitalName, country: self)
|
||||
}
|
||||
}
|
||||
|
||||
class City {
|
||||
let name: String
|
||||
unowned let country: Country
|
||||
init(name: String, country: Country) {
|
||||
self.name = name
|
||||
self.country = country
|
||||
}
|
||||
}
|
||||
</code></pre><p>为了建立两个类的依赖关系,City的构造函数有一个Country实例的参数,并且将实例保存为country属性。</p>
|
||||
<p>Country的构造函数调用了City的构造函数。然而,只有Country的实例完全初始化完后,Country的构造函数才能把self传给City的构造函数。(<a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.html#//apple_ref/doc/uid/TP40014097-CH18-XID_288" target="_blank">在两阶段构造函数中有具体描述</a>)</p>
|
||||
<p>为了满足这种需求,通过在类型结尾处加上感叹号(City!)的方式,将Country的capitalCity属性声明为显示展开的可选类型属性。这表示像其他可选类型一样,capitalCity属性的默认值为nil,但是不需要展开他的值就能访问它。(<a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html#//apple_ref/doc/uid/TP40014097-CH5-XID_436" target="_blank">在显示展开的可选类型中有描述</a>)</p>
|
||||
<p>由于capitalCity默认值为nil,一旦Country的实例在构造函数中给name属性赋值后,整个初始化过程就完成了。这代表一旦name属性被后,Country的构造函数就能引用并传递显式的self。Country的构造函数在赋值capitalCity时,就能将self作为参数传递给City的构造函数。</p>
|
||||
<p>以上的意义在于你可以通过一条语句同时创建Country和City的实例,而不产生循环强引用,并且capitalCity的属性能被直接访问,而不需要通过感叹号来展开它的可选值:</p>
|
||||
<pre><code>var country = Country(name: "Canada", capitalName: "Ottawa")
|
||||
println("\(country.name)'s capital city is called \(country.capitalCity.name)")
|
||||
// prints "Canada's capital city is called Ottawa"
|
||||
</code></pre><p>在上面的例子中,使用显示展开可选值的意义在于满足了两个类构造函数的需求。capitalCity属性在初始化完成后,能作为非可选值使用同事还避免了循环强引用。</p>
|
||||
<h2 id="-">闭包引起的循环强引用</h2>
|
||||
<p>前面我们看到了循环强引用环是在两个类实例属性互相保持对方的强引用时产生的,还知道了如何用弱引用和无主引用来打破循环强引用。</p>
|
||||
<p>循环强引用还会发生在当你将一个闭包赋值给类实例的某个属性,并且这个闭包体中又使用了实例。这个闭包体中可能访问了实例的某个属性,例如self.someProperty,或者闭包中调用了实例的某个方法,例如self.someMethod。这两种情况都导致了闭包 “捕获" self,从而产生了循环强引用。</p>
|
||||
<p>循环强引用的产生,是因为闭包和类相似,都是引用类型。当你把一个闭包赋值给某个属性时,你也把一个引用赋值给了这个闭包。实质上,这跟之前的问题是一样的-两个强引用让彼此一直有效。但是,和两个类实例不同,这次一个是类实例,另一个是闭包。</p>
|
||||
<p>Swift提供了一种优雅的方法来解决这个问题,称之为闭包占用列表(closuer capture list)。同样的,在学习如何用闭包占用列表破坏循环强引用之前,先来了解一下循环强引用是如何产生的,这对我们是很有帮助的。</p>
|
||||
<p>下面的例子为你展示了当一个闭包引用了self后是如何产生一个循环强引用的。例子中定义了一个叫HTMLElement的类,用一种简单的模型表示HTML中的一个单独的元素:</p>
|
||||
<pre><code>class HTMLElement {
|
||||
|
||||
let name: String
|
||||
let text: String?
|
||||
|
||||
@lazy var asHTML: () -> String = {
|
||||
if let text = self.text {
|
||||
return "<\(self.name)>\(text)</\(self.name)>"
|
||||
} else {
|
||||
return "<\(self.name) />"
|
||||
}
|
||||
}
|
||||
|
||||
init(name: String, text: String? = nil) {
|
||||
self.name = name
|
||||
self.text = text
|
||||
}
|
||||
|
||||
deinit {
|
||||
println("\(name) is being deinitialized")
|
||||
}
|
||||
|
||||
}
|
||||
</code></pre><p>HTMLElement类定义了一个name属性来表示这个元素的名称,例如代表段落的"p",或者代表换行的"br"。HTMLElement还定义了一个可选属性text,用来设置和展现HTML元素的文本。</p>
|
||||
<p>除了上面的两个属性,HTMLElement还定义了一个lazy属性asHTML。这个属性引用了一个闭包,将name和text组合成HTML字符串片段。该属性是() -> String类型,或者可以理解为“一个没有参数,返回String的函数”。</p>
|
||||
<p>默认情况下,闭包赋值给了asHTML属性,这个闭包返回一个代表HTML标签的字符串。如果text值存在,该标签就包含可选值text;如果text不存在,该标签就不包含文本。对于段落元素,根据text是"some text"还是nil,闭包会返回"<code><p>some text</p></code>"或者"<code><p /></code>"。</p>
|
||||
<p>可以像实例方法那样去命名、使用asHTML属性。然而,由于asHTML是闭包而不是实例方法,如果你想改变特定元素的HTML处理的话,可以用自定义的闭包来取代默认值。</p>
|
||||
<blockquote>
|
||||
<p>注意: asHTML声明为lazy属性,因为只有当元素确实需要处理为HTML输出的字符串时,才需要使用asHTML。也就是说,在默认的闭包中可以使用self,因为只有当初始化完成以及self确实存在后,才能访问lazy属性。</p>
|
||||
</blockquote>
|
||||
<p>HTMLElement类只提供一个构造函数,通过name和text(如果有的话)参数来初始化一个元素。该类也定义了一个析构函数,当HTMLElement实例被销毁时,打印一条消息。</p>
|
||||
<p>下面的代码展示了如何用HTMLElement类创建实例并打印消息。</p>
|
||||
<pre><code>var paragraph: HTMLElement? = HTMLElement(name: "p", text: "hello, world")
|
||||
println(paragraph!.asHTML())
|
||||
// prints"hello, world"
|
||||
</code></pre><blockquote>
|
||||
<p>注意: 上面的paragraph变量定义为可选HTMLElement,因此我们可以赋值nil给它来演示循环强引用。 </p>
|
||||
</blockquote>
|
||||
<p>不幸的是,上面写的HTMLElement类产生了类实例和asHTML默认值的闭包之间的循环强引用。循环强引用如下图所示:</p>
|
||||
<p><img src="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Art/closureReferenceCycle01_2x.png" alt=""></p>
|
||||
<p>实例的asHTML属性持有闭包的强引用。但是,闭包在其闭包体内使用了self(引用了self.name和self.text),因此闭包占有了self,这意味着闭包又反过来持有了HTMLElement实例的强引用。这样两个对象就产生了循环强引用。(更多关于闭包占有值的信息,请参考<a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html#//apple_ref/doc/uid/TP40014097-CH11-XID_129" target="_blank">Capturing Values</a>)。</p>
|
||||
<blockquote>
|
||||
<p>注意: 虽然闭包多次使用了self,它只占有HTMLElement实例的一个强引用。</p>
|
||||
</blockquote>
|
||||
<p>如果设置paragraph变量为nil,打破它持有的HTMLElement实例的强引用,HTMLElement实例和它的闭包都不会被销毁,也是因为循环强引用:</p>
|
||||
<pre><code>paragraph = nil
|
||||
</code></pre><p>注意HTMLElementdeinitializer中的消息并没有别打印,证明了HTMLElement实例并没有被销毁。</p>
|
||||
<h2 id="-">解决闭包引起的循环强引用</h2>
|
||||
<p>在定义闭包时同时定义占有列表作为闭包的一部分,通过这种方式可以解决闭包和类实例之间的循环强引用。占有列表定义了闭包体内占有一个或者多个引用类型的规则。跟解决两个类实例间的循环强引用一样,声明每个占有的引用为弱引用或无主引用,而不是强引用。应当根据代码关系来决定使用弱引用还是无主引用。</p>
|
||||
<blockquote>
|
||||
<p>注意: Swift有如下要求:只要在闭包内使用self的成员,就要用self.someProperty或者self.someMethod(而不只是someProperty或someMethod)。这提醒你可能会不小心就占有了self。</p>
|
||||
</blockquote>
|
||||
<h2 id="-">定义占有列表</h2>
|
||||
<p>占有列表中的每个元素都是由weak或者unowned关键字和实例的引用(如self或someInstance)成对组成。每一对都在花括号中,通过逗号分开。</p>
|
||||
<p>占有列表放置在闭包参数列表和返回类型之前:</p>
|
||||
<pre><code>@lazy var someClosure: (Int, String) -> String = {
|
||||
[unowned self] (index: Int, stringToProcess: String) -> String in
|
||||
// closure body goes here
|
||||
}
|
||||
</code></pre><p>如果闭包没有指定参数列表或者返回类型,则可以通过上下文推断,那么可以占有列表放在闭包开始的地方,跟着是关键字in:</p>
|
||||
<pre><code>@lazy var someClosure: () -> String = {
|
||||
[unowned self] in
|
||||
// closure body goes here
|
||||
}
|
||||
</code></pre><h2 id="-">弱引用和无主引用</h2>
|
||||
<p>当闭包和占有的实例总是互相引用时并且总是同时销毁时,将闭包内的占有定义为无主引用。</p>
|
||||
<p>相反的,当占有引用有时可能会是nil时,将闭包内的占有定义为弱引用。弱引用总是可选类型,并且当引用的实例被销毁后,弱引用的值会自动置为nil。这使我们可以在闭包内检查他们是否存在。</p>
|
||||
<blockquote>
|
||||
<p>注意: 如果占有的引用绝对不会置为nil,应该用无主引用,而不是弱引用。</p>
|
||||
</blockquote>
|
||||
<p>前面的HTMLElement例子中,无主引用是正确的解决循环强引用的方法。这样这样编写HTMLElement类来避免循环强引用:</p>
|
||||
<pre><code>class HTMLElement {
|
||||
|
||||
let name: String
|
||||
let text: String?
|
||||
|
||||
@lazy var asHTML: () -> String = {
|
||||
[unowned self] in
|
||||
if let text = self.text {
|
||||
return "<\(self.name)>\(text)</\(self.name)>"
|
||||
} else {
|
||||
return "<\(self.name) />"
|
||||
}
|
||||
}
|
||||
|
||||
init(name: String, text: String? = nil) {
|
||||
self.name = name
|
||||
self.text = text
|
||||
}
|
||||
|
||||
deinit {
|
||||
println("\(name) is being deinitialized")
|
||||
}
|
||||
|
||||
}
|
||||
</code></pre><p>上面的HTMLElement实现和之前的实现一致,只是在asHTML闭包中多了一个占有列表。这里,占有列表是[unowned self],表示“用无主引用而不是强引用来占有self”。</p>
|
||||
<p>和之前一样,我们可以创建并打印HTMLElement实例:</p>
|
||||
<pre><code>var paragraph: HTMLElement? = HTMLElement(name: "p", text: "hello, world")
|
||||
println(paragraph!.asHTML())
|
||||
// prints "<p>hello, world</p>"
|
||||
</code></pre><p>使用占有列表后引用关系如下图所示:</p>
|
||||
<p><img src="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Art/closureReferenceCycle02_2x.png" alt=""></p>
|
||||
<p>这一次,闭包以无主引用的形式占有self,并不会持有HTMLElement实例的强引用。如果将paragraph赋值为nil,HTMLElement实例将会被销毁,并能看到它的析构函数打印出的消息。</p>
|
||||
<pre><code>paragraph = nil
|
||||
// prints "p is being deinitialized"
|
||||
</code></pre>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.17" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.17" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
@ -587,7 +587,7 @@
|
||||
|
||||
<div class="page-inner">
|
||||
|
||||
<section class="normal" id="section-gitbook_66">
|
||||
<section class="normal" id="section-gitbook_34">
|
||||
|
||||
<h1 id="optional-chaining">Optional Chaining</h1>
|
||||
<p>可选链(Optional Chaining)是一种可以请求和调用属性、方法及子脚本的过程,它的自判断性体现于请求或调用的目标当前可能为空(<code>nil</code>)。如果自判断的目标有值,那么调用就会成功;相反,如果选择的目标为空(<code>nil</code>),则这种调用将返回空(<code>nil</code>)。多次请求或调用可以被链接在一起形成一个链,如果任何一个节点为空(<code>nil</code>)将导致整个链失效。</p>
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.18" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.18" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
@ -587,7 +587,7 @@
|
||||
|
||||
<div class="page-inner">
|
||||
|
||||
<section class="normal" id="section-gitbook_67">
|
||||
<section class="normal" id="section-gitbook_35">
|
||||
|
||||
<h1 id="-type-casting-">类型检查(Type Casting)</h1>
|
||||
<p>(ps:为了方便各位检验所以保留了英文,可删。)
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.19" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.19" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter done " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
@ -587,7 +587,7 @@
|
||||
|
||||
<div class="page-inner">
|
||||
|
||||
<section class="normal" id="section-gitbook_68">
|
||||
<section class="normal" id="section-gitbook_36">
|
||||
|
||||
<h1 id="-">类型嵌套</h1>
|
||||
<p>本页包含内容:</p>
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.20" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.20" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter done " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
@ -587,7 +587,7 @@
|
||||
|
||||
<div class="page-inner">
|
||||
|
||||
<section class="normal" id="section-gitbook_69">
|
||||
<section class="normal" id="section-gitbook_37">
|
||||
|
||||
<h1 id="-extensions-">扩展(Extensions)</h1>
|
||||
<hr>
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.21" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.21" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter done " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.22" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.22" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter done " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
@ -587,7 +587,7 @@
|
||||
|
||||
<div class="page-inner">
|
||||
|
||||
<section class="normal" id="section-gitbook_72">
|
||||
<section class="normal" id="section-gitbook_40">
|
||||
|
||||
<h1 id="-">泛型</h1>
|
||||
<hr>
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2.23" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2.23" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter done " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter done " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter done " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="book" data-level="2" data-basepath=".." data-revision="1402287112409">
|
||||
<div class="book" data-level="2" data-basepath=".." data-revision="1402299637539">
|
||||
<div class="book-header">
|
||||
<!-- Actions Left -->
|
||||
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
|
||||
@ -178,7 +178,7 @@
|
||||
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html">
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本操作符
|
||||
<i class="fa fa-check"></i> <b>2.2.</b> 基本运算符
|
||||
</a>
|
||||
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html">
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 下标
|
||||
<i class="fa fa-check"></i> <b>2.12.</b> 附属脚本
|
||||
</a>
|
||||
|
||||
|
||||
@ -520,7 +520,7 @@
|
||||
|
||||
<a href="../chapter2/11_Methods.html" title="方法" class="chapter " data-progress="2.11" style="left: 18.42105263157895%;"></a>
|
||||
|
||||
<a href="../chapter2/12_Subscripts.html" title="下标" class="chapter " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
<a href="../chapter2/12_Subscripts.html" title="附属脚本" class="chapter " data-progress="2.12" style="left: 21.05263157894737%;"></a>
|
||||
|
||||
<a href="../chapter2/13_Inheritance.html" title="继承" class="chapter " data-progress="2.13" style="left: 23.68421052631579%;"></a>
|
||||
|
||||
@ -536,7 +536,7 @@
|
||||
|
||||
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter " data-progress="2.19" style="left: 39.473684210526315%;"></a>
|
||||
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本操作符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
<a href="../chapter2/02_Basic_Operators.html" title="基本运算符" class="chapter " data-progress="2.2" style="left: 42.10526315789474%;"></a>
|
||||
|
||||
<a href="../chapter2/20_Extensions.html" title="扩展" class="chapter " data-progress="2.20" style="left: 44.73684210526316%;"></a>
|
||||
|
||||
@ -587,7 +587,7 @@
|
||||
|
||||
<div class="page-inner">
|
||||
|
||||
<section class="normal" id="section-gitbook_76">
|
||||
<section class="normal" id="section-gitbook_44">
|
||||
|
||||
<h1 id="swift-">Swift 教程</h1>
|
||||
<p>本章介绍了 Swift 的各种特性及其使用方法,是全书的核心部分。</p>
|
||||
|
||||
Reference in New Issue
Block a user