update 2 new article

This commit is contained in:
numbbbbb
2014-06-09 15:40:59 +08:00
parent 992719afd0
commit f8cae9a036
42 changed files with 802 additions and 236 deletions

View File

@ -46,7 +46,7 @@
<div class="book" data-level="1.1" data-basepath=".." data-revision="1402287112409"> <div class="book" data-level="1.1" data-basepath=".." data-revision="1402299637539">
<div class="book-header"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_36"> <section class="normal" id="section-gitbook_4">
<h1 id="-swift">关于 Swift</h1> <h1 id="-swift">关于 Swift</h1>
<p>Swift 是一种新的编程语言,用于编写 iOS 和 OS X 应用。Swift 结合了 C 和 Objective-C 的优点并且不受C的兼容性的限制。Swift 使用安全的编程模式并添加了很多新特性这将使编程更简单扩展性更强也更有趣。除此之外Swift 还支持人见人爱的 Cocoa 和 Cocoa Touch 框架。拥有了这些特性Swift将重新定义软件开发。</p> <p>Swift 是一种新的编程语言,用于编写 iOS 和 OS X 应用。Swift 结合了 C 和 Objective-C 的优点并且不受C的兼容性的限制。Swift 使用安全的编程模式并添加了很多新特性这将使编程更简单扩展性更强也更有趣。除此之外Swift 还支持人见人爱的 Cocoa 和 Cocoa Touch 框架。拥有了这些特性Swift将重新定义软件开发。</p>

View File

@ -46,7 +46,7 @@
<div class="book" data-level="1.2" data-basepath=".." data-revision="1402287112409"> <div class="book" data-level="1.2" data-basepath=".." data-revision="1402299637539">
<div class="book-header"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_37"> <section class="normal" id="section-gitbook_5">
<h1 id="swift-">Swift 初见</h1> <h1 id="swift-">Swift 初见</h1>
<p>本页内容包括:</p> <p>本页内容包括:</p>
@ -662,7 +662,7 @@ for score in individualScores {
} }
teamScore teamScore
</code></pre><p><code>if</code>语句中,条件必须是一个布尔表达式——这意味着像<code>if score { ... }</code>这样的代码将报错,而不会隐形地与 0 做对比。</p> </code></pre><p><code>if</code>语句中,条件必须是一个布尔表达式——这意味着像<code>if score { ... }</code>这样的代码将报错,而不会隐形地与 0 做对比。</p>
<p>你可以一起使用<code>if</code><code>let</code>来处理值缺失的情况。有些变量的值是可选的。一个可选的值可能是一个具体的值或者是<code>nil</code>,表示值缺失。在类型后面加一个<code>?</code>来标记这个变量的值是可选的。</p> <p>你可以一起使用<code>if</code><code>let</code>来处理值缺失的情况。有些变量的值是可选的。一个可选的值可能是一个具体的值或者是<code>nil</code>,表示值缺失。在类型后面加一个问号来标记这个变量的值是可选的。</p>
<pre><code>var optionalString: String? = &quot;Hello&quot; <pre><code>var optionalString: String? = &quot;Hello&quot;
optionalString == nil optionalString == nil

View File

@ -46,7 +46,7 @@
<div class="book" data-level="1" data-basepath=".." data-revision="1402287112409"> <div class="book" data-level="1" data-basepath=".." data-revision="1402299637539">
<div class="book-header"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_38"> <section class="normal" id="section-gitbook_6">
<h1 id="-swift">欢迎使用 Swift</h1> <h1 id="-swift">欢迎使用 Swift</h1>
<p>在本章中您将了解 Swift 的特性和开发历史,并对 Swift 有一个初步的了解。</p> <p>在本章中您将了解 Swift 的特性和开发历史,并对 Swift 有一个初步的了解。</p>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_40"> <section class="normal" id="section-gitbook_8">
<h1 id="-">基础部分</h1> <h1 id="-">基础部分</h1>
<p>Swift 是 iOS 和 OS X 应用开发的一门新语言。然而,如果你有 C 或者 Objective-C 开发经验的话,你会发现 Swift 的很多内容都是你熟悉的。</p> <p>Swift 是 iOS 和 OS X 应用开发的一门新语言。然而,如果你有 C 或者 Objective-C 开发经验的话,你会发现 Swift 的很多内容都是你熟悉的。</p>
@ -978,7 +978,7 @@ assert(age &gt;= 0, &quot;A person&#39;s age cannot be less than zero&quot;)
<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/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>
</div> </div>

View File

@ -5,7 +5,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>基本操作符 | Swift 编程语言</title> <title>基本运算符 | Swift 编程语言</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="robots" content="index, follow"> <meta name="robots" content="index, follow">
@ -21,7 +21,7 @@
<link rel="prev" href="../chapter2/01_The_Basics.html" /> <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:site_name" content="Swift 编程语言">
<meta property="og:type" content="book"> <meta property="og:type" content="book">
<meta property="og:locale" content="en_US"> <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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_62"> <section class="normal" id="section-gitbook_30">
<h1 id="-">基础运算符</h1> <h1 id="-">基础运算符</h1>
<p>运算符是检查, 改变, 合并值的特殊符号或短语. 例如, 加号 <code>+</code> 把计算两个数的和(如 <code>let i = 1 + 2</code>). 复杂些的运行算包括逻辑与<code>&amp;&amp;</code>(如 <code>if enteredDoorCode &amp;&amp; passedRetinaScan</code>), 还有自增运算符 <code>++i</code> 这样让自身加一的便捷运算.</p> <p>运算符是检查, 改变, 合并值的特殊符号或短语. 例如, 加号 <code>+</code> 把计算两个数的和(如 <code>let i = 1 + 2</code>). 复杂些的运行算包括逻辑与<code>&amp;&amp;</code>(如 <code>if enteredDoorCode &amp;&amp; passedRetinaScan</code>), 还有自增运算符 <code>++i</code> 这样让自身加一的便捷运算.</p>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <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> <h1 id="-strings-and-characters-">字符串和字符 (Strings and Characters)</h1>
<p>本页包含内容:</p> <p>本页包含内容:</p>
@ -877,7 +877,7 @@ print(&quot;\n&quot;)
</div> </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> <a href="../chapter2/04_Collection_Types.html" class="navigation navigation-next " aria-label="Next page: 集合类型"><i class="fa fa-angle-right"></i></a>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_55"> <section class="normal" id="section-gitbook_23">
<h1 id="-functions-">函数Functions</h1> <h1 id="-functions-">函数Functions</h1>
<p>本页包含内容:</p> <p>本页包含内容:</p>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_56"> <section class="normal" id="section-gitbook_24">
<h1 id="-">闭包</h1> <h1 id="-">闭包</h1>
<p>本页内容包含:</p> <p>本页内容包含:</p>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_57"> <section class="normal" id="section-gitbook_25">
<h1 id="-">枚举</h1> <h1 id="-">枚举</h1>
<p>本页内容包含:</p> <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> </code></pre><p><code>directionToHead</code>的类型被推断当它被<code>CompassPoint</code>的一个可能值初始化。一旦<code>directionToHead</code>被声明为一个<code>CompassPoint</code>,你可以使用更短的点(.)语法将其设置为另一个<code>CompassPoint</code>的值:</p>
<pre><code>directionToHead = .East <pre><code>directionToHead = .East
</code></pre><p><code>directionToHead</code>的类型已知时,当设定它的值时,你可以不再写类型名。使用显示类型的枚举值可以让代码具有更好的可读性。</p> </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> <p>你可以匹配单个枚举值和<code>switch</code>语句:</p>
<pre><code>directionToHead = .South <pre><code>directionToHead = .South
switch directionToHead { switch directionToHead {

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_58"> <section class="normal" id="section-gitbook_26">
<h3 id="-">类和结构体</h3> <h3 id="-">类和结构体</h3>
<p>本页包含内容:</p> <p>本页包含内容:</p>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <a href="../chapter2/20_Extensions.html" title="扩展" class="chapter " data-progress="2.20" style="left: 44.73684210526316%;"></a>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_60"> <section class="normal" id="section-gitbook_28">
<h1 id="-methods-">方法(Methods)</h1> <h1 id="-methods-">方法(Methods)</h1>
<p><strong>方法</strong>是与某些特定类型相关联的功能/函数。类、结构体、枚举都可以定义实例方法;实例方法为指定类型的实例封装了特定的任务与功能。类、结构体、枚举也可以定义类(型)方法(type itself)类型方法与类型自身相关联。类型方法与Objective-C中的类方法(class methods)相似。</p> <p><strong>方法</strong>是与某些特定类型相关联的功能/函数。类、结构体、枚举都可以定义实例方法;实例方法为指定类型的实例封装了特定的任务与功能。类、结构体、枚举也可以定义类(型)方法(type itself)类型方法与类型自身相关联。类型方法与Objective-C中的类方法(class methods)相似。</p>
@ -798,7 +798,7 @@ println(&quot;level 6 has not yet been unlocked&quot;)
<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/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>
</div> </div>

View File

@ -5,7 +5,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>下标 | Swift 编程语言</title> <title>附属脚本 | Swift 编程语言</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="robots" content="index, follow"> <meta name="robots" content="index, follow">
@ -21,7 +21,7 @@
<link rel="prev" href="../chapter2/11_Methods.html" /> <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:site_name" content="Swift 编程语言">
<meta property="og:type" content="book"> <meta property="og:type" content="book">
<meta property="og:locale" content="en_US"> <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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_61"> <section class="normal" id="section-gitbook_29">
<h1 id="-subscripts-">下标 (Subscripts)</h1> <h1 id="-subscripts-">下标 (Subscripts)</h1>
<p>下标可以定义在类(Class)、结构体(structures)和枚举(enumerations)这些目标中,可以认为是访问对象、集合或序列的快捷方式。举例来说,用下标访问一个数组(Array)实例中的元素可以这样写 <code>someArray[index]</code> ,访问字典(Dictionary)实例中的元素可以这样写 <code>someDictionary[key]</code>,而不需要再调用实例的某个方法来获得元素的值。</p> <p>下标可以定义在类(Class)、结构体(structures)和枚举(enumerations)这些目标中,可以认为是访问对象、集合或序列的快捷方式。举例来说,用下标访问一个数组(Array)实例中的元素可以这样写 <code>someArray[index]</code> ,访问字典(Dictionary)实例中的元素可以这样写 <code>someDictionary[key]</code>,而不需要再调用实例的某个方法来获得元素的值。</p>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_39"> <section class="normal" id="section-gitbook_7">
<h1 id="-">继承</h1> <h1 id="-">继承</h1>
<p>一个类可以继承另一个类的方法属性和其它特性。当一个类继承其它类继承类叫子类被继承类叫超类或父类。在Swift中继承是区分「类」与其它类型的一个基本特征。</p> <p>一个类可以继承另一个类的方法属性和其它特性。当一个类继承其它类继承类叫子类被继承类叫超类或父类。在Swift中继承是区分「类」与其它类型的一个基本特征。</p>
@ -755,7 +755,7 @@ println(&quot;AutomaticCar: \(automatic.description())&quot;)
</div> </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> <a href="../chapter2/14_Initialization.html" class="navigation navigation-next " aria-label="Next page: 构造过程"><i class="fa fa-angle-right"></i></a>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <a href="../chapter2/20_Extensions.html" title="扩展" class="chapter " data-progress="2.20" style="left: 44.73684210526316%;"></a>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_64"> <section class="normal" id="section-gitbook_32">
<h1 id="-">析构过程</h1> <h1 id="-">析构过程</h1>
<p>在一个类的实例被释放之前析构函数被立即调用。用关键字deinit来标示析构函数类似于初始化函数用init来标示。析构函数只适用于类类型。</p> <p>在一个类的实例被释放之前析构函数被立即调用。用关键字deinit来标示析构函数类似于初始化函数用init来标示。析构函数只适用于类类型。</p>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_65"> <section class="normal" id="section-gitbook_33">
<h1 id="-">自动引用计数</h1> <h1 id="-">自动引用计数</h1>
<p>本页包含内容:</p> <p>本页包含内容:</p>
@ -607,10 +607,320 @@
<h2 id="-">自动引用计数的工作机制</h2> <h2 id="-">自动引用计数的工作机制</h2>
<p>当你每次创建一个类的新的实例的时候ARC会分配一大块内存用来储存实例的信息。内存中会包含实例的类型信息以及这个实例所有相关属性的值。此外当实例不再被使用时ARC释放实例所占用的内存并让释放的内存能挪作他用。这确保了不再被使用的实例不会一直占用内存空间。</p> <p>当你每次创建一个类的新的实例的时候ARC会分配一大块内存用来储存实例的信息。内存中会包含实例的类型信息以及这个实例所有相关属性的值。此外当实例不再被使用时ARC释放实例所占用的内存并让释放的内存能挪作他用。这确保了不再被使用的实例不会一直占用内存空间。</p>
<p>然而当ARC收回和释放了正在被使用中的实例该实例的属性和方法将不能再被访问和调用。实际上如果你试图访问这个实例你的应用程序很可能会崩溃。</p> <p>然而当ARC收回和释放了正在被使用中的实例该实例的属性和方法将不能再被访问和调用。实际上如果你试图访问这个实例你的应用程序很可能会崩溃。</p>
<p>为了确保使用中的实例不会被回收ARC会跟踪和计算每一个实例正在被多少属性常量和变量所引用。哪怕实例的引用数为一ARC都不会回收这个实例。</p> <p>为了确保使用中的实例不会被销毁ARC会跟踪和计算每一个实例正在被多少属性常量和变量所引用。哪怕实例的引用数为一ARC都不会销毁这个实例。</p>
<p>为了使之成为可能,无论你将实例赋值给属性,常量或者是变量,属性,常量或者变量,都会对此实例创建强引用。之所以称之为强引用,是因为它会将实例牢牢的保持住,只要强引用还在,实例是不允许被释放的。</p> <p>为了使之成为可能,无论你将实例赋值给属性,常量或者是变量,属性,常量或者变量,都会对此实例创建强引用。之所以称之为强引用,是因为它会将实例牢牢的保持住,只要强引用还在,实例是不允许被销毁的。</p>
<h2 id="-">自动引用计数实</h2> <h2 id="-">自动引用计数实</h2>
<p>下面的例子展示了自动引用计数的工作机制。例子以一个简单的Person类开始并定义了一个叫name的常量属性</p>
<pre><code> class Person {
let name: String
init(name: String) {
self.name = name
println(&quot;\(name) is being initialized&quot;)
}
deinit {
println(&quot;\(name) is being deinitialized&quot;)
}
}
</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: &quot;John Appleseed&quot;)
// prints &quot;John Appleseed is being initialized”
</code></pre><p>应当注意到当你调用Person类的构造函数的时候&quot;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 &quot;John Appleseed is being deinitialized&quot;
</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(&quot;\(name) is being deinitialized&quot;) }
}
class Apartment {
let number: Int
init(number: Int) { self.number = number }
var tenant: Person?
deinit { println(&quot;Apartment #\(number) is being deinitialized&quot;) }
}
</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: &quot;John Appleseed&quot;)
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(&quot;\(name) is being deinitialized&quot;) }
}
class Apartment {
let number: Int
init(number: Int) { self.number = number }
weak var tenant: Person?
deinit { println(&quot;Apartment #\(number) is being deinitialized&quot;) }
}
</code></pre><p>然后跟之前一样,建立两个变量(john和number73)之间的强引用,并关联两个实例:</p>
<pre><code>var john: Person?
var number73: Apartment?
john = Person(name: &quot;John Appleseed&quot;)
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 &quot;John Appleseed is being deinitialized&quot;
</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 &quot;Apartment #73 is being deinitialized&quot;
</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(&quot;\(name) is being deinitialized&quot;) }
}
class CreditCard {
let number: Int
unowned let customer: Customer
init(number: Int, customer: Customer) {
self.number = number
self.customer = customer
}
deinit { println(&quot;Card #\(number) is being deinitialized&quot;) }
}
</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: &quot;John Appleseed&quot;)
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 &quot;John Appleseed is being deinitialized&quot;
// prints &quot;Card #1234567890123456 is being deinitialized&quot;
</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: &quot;Canada&quot;, capitalName: &quot;Ottawa&quot;)
println(&quot;\(country.name)&#39;s capital city is called \(country.capitalCity.name)&quot;)
// prints &quot;Canada&#39;s capital city is called Ottawa&quot;
</code></pre><p>在上面的例子中使用显示展开可选值的意义在于满足了两个类构造函数的需求。capitalCity属性在初始化完成后能作为非可选值使用同事还避免了循环强引用。</p>
<h2 id="-">闭包引起的循环强引用</h2>
<p>前面我们看到了循环强引用环是在两个类实例属性互相保持对方的强引用时产生的,还知道了如何用弱引用和无主引用来打破循环强引用。</p>
<p>循环强引用还会发生在当你将一个闭包赋值给类实例的某个属性并且这个闭包体中又使用了实例。这个闭包体中可能访问了实例的某个属性例如self.someProperty或者闭包中调用了实例的某个方法例如self.someMethod。这两种情况都导致了闭包 “捕获&quot; 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: () -&gt; String = {
if let text = self.text {
return &quot;&lt;\(self.name)&gt;\(text)&lt;/\(self.name)&gt;&quot;
} else {
return &quot;&lt;\(self.name) /&gt;&quot;
}
}
init(name: String, text: String? = nil) {
self.name = name
self.text = text
}
deinit {
println(&quot;\(name) is being deinitialized&quot;)
}
}
</code></pre><p>HTMLElement类定义了一个name属性来表示这个元素的名称例如代表段落的&quot;p&quot;,或者代表换行的&quot;br&quot;。HTMLElement还定义了一个可选属性text用来设置和展现HTML元素的文本。</p>
<p>除了上面的两个属性HTMLElement还定义了一个lazy属性asHTML。这个属性引用了一个闭包将name和text组合成HTML字符串片段。该属性是() -&gt; String类型或者可以理解为“一个没有参数返回String的函数”。</p>
<p>默认情况下闭包赋值给了asHTML属性这个闭包返回一个代表HTML标签的字符串。如果text值存在该标签就包含可选值text如果text不存在该标签就不包含文本。对于段落元素根据text是&quot;some text&quot;还是nil闭包会返回&quot;<code>&lt;p&gt;some text&lt;/p&gt;</code>&quot;或者&quot;<code>&lt;p /&gt;</code>&quot;</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: &quot;p&quot;, text: &quot;hello, world&quot;)
println(paragraph!.asHTML())
// prints&quot;hello, world&quot;
</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) -&gt; String = {
[unowned self] (index: Int, stringToProcess: String) -&gt; String in
// closure body goes here
}
</code></pre><p>如果闭包没有指定参数列表或者返回类型则可以通过上下文推断那么可以占有列表放在闭包开始的地方跟着是关键字in</p>
<pre><code>@lazy var someClosure: () -&gt; 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: () -&gt; String = {
[unowned self] in
if let text = self.text {
return &quot;&lt;\(self.name)&gt;\(text)&lt;/\(self.name)&gt;&quot;
} else {
return &quot;&lt;\(self.name) /&gt;&quot;
}
}
init(name: String, text: String? = nil) {
self.name = name
self.text = text
}
deinit {
println(&quot;\(name) is being deinitialized&quot;)
}
}
</code></pre><p>上面的HTMLElement实现和之前的实现一致只是在asHTML闭包中多了一个占有列表。这里占有列表是[unowned self]表示“用无主引用而不是强引用来占有self”。</p>
<p>和之前一样我们可以创建并打印HTMLElement实例</p>
<pre><code>var paragraph: HTMLElement? = HTMLElement(name: &quot;p&quot;, text: &quot;hello, world&quot;)
println(paragraph!.asHTML())
// prints &quot;&lt;p&gt;hello, world&lt;/p&gt;&quot;
</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赋值为nilHTMLElement实例将会被销毁并能看到它的析构函数打印出的消息。</p>
<pre><code>paragraph = nil
// prints &quot;p is being deinitialized&quot;
</code></pre>
</section> </section>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <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> <h1 id="optional-chaining">Optional Chaining</h1>
<p>可选链Optional Chaining是一种可以请求和调用属性、方法及子脚本的过程它的自判断性体现于请求或调用的目标当前可能为空<code>nil</code>)。如果自判断的目标有值,那么调用就会成功;相反,如果选择的目标为空(<code>nil</code>),则这种调用将返回空(<code>nil</code>)。多次请求或调用可以被链接在一起形成一个链,如果任何一个节点为空(<code>nil</code>)将导致整个链失效。</p> <p>可选链Optional Chaining是一种可以请求和调用属性、方法及子脚本的过程它的自判断性体现于请求或调用的目标当前可能为空<code>nil</code>)。如果自判断的目标有值,那么调用就会成功;相反,如果选择的目标为空(<code>nil</code>),则这种调用将返回空(<code>nil</code>)。多次请求或调用可以被链接在一起形成一个链,如果任何一个节点为空(<code>nil</code>)将导致整个链失效。</p>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <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> <h1 id="-type-casting-">类型检查Type Casting</h1>
<p>ps为了方便各位检验所以保留了英文可删。 <p>ps为了方便各位检验所以保留了英文可删。

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_68"> <section class="normal" id="section-gitbook_36">
<h1 id="-">类型嵌套</h1> <h1 id="-">类型嵌套</h1>
<p>本页包含内容:</p> <p>本页包含内容:</p>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_69"> <section class="normal" id="section-gitbook_37">
<h1 id="-extensions-">扩展Extensions</h1> <h1 id="-extensions-">扩展Extensions</h1>
<hr> <hr>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_72"> <section class="normal" id="section-gitbook_40">
<h1 id="-">泛型</h1> <h1 id="-">泛型</h1>
<hr> <hr>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>

View File

@ -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"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_76"> <section class="normal" id="section-gitbook_44">
<h1 id="swift-">Swift 教程</h1> <h1 id="swift-">Swift 教程</h1>
<p>本章介绍了 Swift 的各种特性及其使用方法,是全书的核心部分。</p> <p>本章介绍了 Swift 的各种特性及其使用方法,是全书的核心部分。</p>

View File

@ -46,7 +46,7 @@
<div class="book" data-level="3.1" data-basepath=".." data-revision="1402287112409"> <div class="book" data-level="3.1" data-basepath=".." data-revision="1402299637539">
<div class="book-header"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_78"> <section class="normal" id="section-gitbook_46">
<h1 id="-">关于语言附注</h1> <h1 id="-">关于语言附注</h1>
<p>本书的这一节描述了Swift编程语言的形式语法。这里描述的语法是为了帮助您更详细的了解该语言而不是让您直接实现一个解析器或编译器。</p> <p>本书的这一节描述了Swift编程语言的形式语法。这里描述的语法是为了帮助您更详细的了解该语言而不是让您直接实现一个解析器或编译器。</p>

View File

@ -46,7 +46,7 @@
<div class="book" data-level="3.2" data-basepath=".." data-revision="1402287112409"> <div class="book" data-level="3.2" data-basepath=".." data-revision="1402299637539">
<div class="book-header"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>

View File

@ -46,7 +46,7 @@
<div class="book" data-level="3.3" data-basepath=".." data-revision="1402287112409"> <div class="book" data-level="3.3" data-basepath=".." data-revision="1402299637539">
<div class="book-header"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>

View File

@ -46,7 +46,7 @@
<div class="book" data-level="3.4" data-basepath=".." data-revision="1402287112409"> <div class="book" data-level="3.4" data-basepath=".." data-revision="1402299637539">
<div class="book-header"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>

View File

@ -46,7 +46,7 @@
<div class="book" data-level="3.6" data-basepath=".." data-revision="1402287112409"> <div class="book" data-level="3.6" data-basepath=".." data-revision="1402299637539">
<div class="book-header"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>

View File

@ -46,7 +46,7 @@
<div class="book" data-level="3.7" data-basepath=".." data-revision="1402287112409"> <div class="book" data-level="3.7" data-basepath=".." data-revision="1402299637539">
<div class="book-header"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <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"> <div class="page-inner">
<section class="normal" id="section-gitbook_77"> <section class="normal" id="section-gitbook_45">
<h1 id="-">特性</h1> <h1 id="-">特性</h1>
<p>特性提供了关于声明和类型的更多信息。在Swift中有两类特性用于修饰声明的以及用于修饰类型的。例如<code>required</code>特性,当应用于一个类的指定或便利初始化器声明时,表明它的每个子类都必须实现那个初始化器。再比如<code>noreturn</code>特性,当应用于函数或方法类型时,表明该函数或方法不会返回到它的调用者。</p> <p>特性提供了关于声明和类型的更多信息。在Swift中有两类特性用于修饰声明的以及用于修饰类型的。例如<code>required</code>特性,当应用于一个类的指定或便利初始化器声明时,表明它的每个子类都必须实现那个初始化器。再比如<code>noreturn</code>特性,当应用于函数或方法类型时,表明该函数或方法不会返回到它的调用者。</p>

View File

@ -46,7 +46,7 @@
<div class="book" data-level="3.8" data-basepath=".." data-revision="1402287112409"> <div class="book" data-level="3.8" data-basepath=".." data-revision="1402299637539">
<div class="book-header"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>

View File

@ -46,7 +46,7 @@
<div class="book" data-level="3.9" data-basepath=".." data-revision="1402287112409"> <div class="book" data-level="3.9" data-basepath=".." data-revision="1402299637539">
<div class="book-header"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>

View File

@ -44,7 +44,7 @@
<div class="book" data-level="3.10" data-basepath=".." data-revision="1402287112409"> <div class="book" data-level="3.10" data-basepath=".." data-revision="1402299637539">
<div class="book-header"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
@ -176,7 +176,7 @@
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -266,7 +266,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </a>
@ -518,7 +518,7 @@
<a href="../chapter2/11_Methods.html" title="方法" class="chapter done " data-progress="2.11" style="left: 18.42105263157895%;"></a> <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> <a href="../chapter2/13_Inheritance.html" title="继承" class="chapter done " data-progress="2.13" style="left: 23.68421052631579%;"></a>
@ -534,7 +534,7 @@
<a href="../chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter done " data-progress="2.19" style="left: 39.473684210526315%;"></a> <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> <a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>

View File

@ -46,7 +46,7 @@
<div class="book" data-level="3.5" data-basepath=".." data-revision="1402287112409"> <div class="book" data-level="3.5" data-basepath=".." data-revision="1402299637539">
<div class="book-header"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>
@ -587,6 +587,262 @@
<div class="page-inner"> <div class="page-inner">
<section class="normal" id="section-gitbook_54">
<h1 id="-">语句</h1>
<p>在 Swift 中有两种类型的语句简单语句和控制流语句。简单语句是最常见的用于构造表达式和声明。控制流语句则用于控制程序执行的流程Swift 中有三种类型的控制流语句:循环语句、分支语句和控制传递语句。</p>
<p>循环语句用于重复执行代码块;分支语句用于执行满足特定条件的代码块;控制传递语句则用于修改代码的执行顺序。在稍后的叙述中,将会详细地介绍每一种类型的控制流语句。</p>
<p>是否将分号(;)添加到语句的结尾处是可选的。但若要在同一行内写多条独立语句,请务必使用分号。</p>
<blockquote>
<p>GRAMMAR OF A STATEMENT</p>
<p><em>statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Expressions.html#//apple_ref/swift/grammar/expression" target="_blank"><em>expression</em></a><strong>;</strong> <em>opt</em></p>
<p><em>statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html#//apple_ref/swift/grammar/declaration" target="_blank"><em>declaration</em></a><strong>;</strong> <em>opt</em></p>
<p><em>statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/loop-statement" target="_blank"><em>loop-statement</em></a><strong>;</strong> <em>opt</em></p>
<p><em>statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/branch-statement" target="_blank"><em>branch-statement</em></a><strong>;</strong> <em>opt</em></p>
<p><em>statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/labeled-statement" target="_blank"><em>labeled-statement</em></a></p>
<p><em>statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/control-transfer-statement" target="_blank"><em>control-transfer-statement</em></a><strong>;</strong> <em>opt</em></p>
<p><em>statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/statement" target="_blank"><em>statment</em></a> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/statements" target="_blank"><em>statements</em></a><strong>;</strong> <em>opt</em></p>
</blockquote>
<h2 id="-">循环语句</h2>
<p>取决于特定的循环条件循环语句允许重复执行代码块。Swift 提供四种类型的循环语句:<code>for</code>语句、<code>for-in</code>语句、<code>while</code>语句和<code>do-while</code>语句。</p>
<p>通过<code>break</code>语句和<code>continue</code>语句可以改变循环语句的控制流。有关这两条语句,请参考<a href=""><em>Break 语句</em><code>待添加链接</code></a><a href=""><em>Continue 语句</em><code>待添加链接</code></a></p>
<blockquote>
<p>GRAMMAR OF A LOOP STATEMENT</p>
<p><em>loop-statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/for-statement" target="_blank"><em>for-statement</em></a></p>
<p><em>loop-statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/for-in-statement" target="_blank"><em>for-in-statement</em></a></p>
<p><em>loop-statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/while-statement" target="_blank"><em>while-statement</em></a></p>
<p><em>loop-statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/do-while-statement" target="_blank"><em>do-while-statement</em></a></p>
</blockquote>
<h3 id="for-">For 语句</h3>
<p><code>for</code>语句允许在重复执行代码块的同时,递增一个计数器。</p>
<p><code>for</code>语句的形式如下:</p>
<pre><code class="lang-swift">for `initialzation`; `condition`; `increment` {
`statements`
}
</code></pre>
<p><em>initialzation</em><em>condition</em><em>increment</em>之间的分号,以及包围循环体<em>statements</em>的大括号都是不可省略的。</p>
<p><code>for</code>语句的执行流程如下:</p>
<ol>
<li><p><em>initialzation</em>只会被执行一次,通常用于声明和初始化在接下来的循环中需要使用的变量。</p>
</li>
<li><p>计算<em>condition</em>表达式:
如果为真(<code>true</code>)<em>statements</em>将会被执行然后转到第3步。如果为假(<code>false</code>)<em>statements</em><em>increment</em>都不会被执行,<code>for</code>至此执行完毕。</p>
</li>
<li><p>计算<em>increment</em>表达式然后转到第2步。</p>
</li>
</ol>
<p>定义在<em>initialzation</em>中的变量仅在<code>for</code>语句的作用域以内有效。<em>condition</em>表达式的值的类型必须符合<code>LogicValue</code>协议。</p>
<blockquote>
<p>GRAMMAR OF A FOR STATEMENT</p>
<p><em>for-statement</em><strong>for</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/for-init" target="_blank"><em>for-init</em></a> <em>opt</em> <strong>;</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Expressions.html#//apple_ref/swift/grammar/expression" target="_blank"><em>expression</em></a> <em>opt</em> <strong>;</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Expressions.html#//apple_ref/swift/grammar/expression" target="_blank"><em>expression</em></a> <em>opt</em> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html#//apple_ref/swift/grammar/code-block" target="_blank"><em>code-block</em></a></p>
<p><em>for-statement</em><strong>for ( </strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/for-init" target="_blank"><em>for-init</em></a> <em>opt</em> <strong>;</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Expressions.html#//apple_ref/swift/grammar/expression" target="_blank"><em>expression</em></a> <em>opt</em> <strong>;</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Expressions.html#//apple_ref/swift/grammar/expression" target="_blank"><em>expression</em></a> <em>opt</em> <strong>)</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html#//apple_ref/swift/grammar/code-block" target="_blank"><em>code-block</em></a></p>
<p><em>for-statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html#//apple_ref/swift/grammar/variable-declaration" target="_blank"><em>variable-declaration</em></a> | <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Expressions.html#//apple_ref/swift/grammar/expression-list" target="_blank"><em>expression-list</em></a></p>
</blockquote>
<h3 id="for-in-">For-In 语句</h3>
<p><code>for-in</code>语句允许在重复执行代码块的同时,迭代集合(或符合<code>Sequence</code>协议的任意类型)中的每一项。</p>
<p><code>for-in</code>语句的形式如下:</p>
<pre><code class="lang-swift">for `item` in `collection` {
`statements`
}
</code></pre>
<p><code>for-in</code>语句在循环开始前会调用<em>collection</em>表达式的<code>generate</code>方法来获取一个生成器类型(这是一个符合<code>Generator</code>协议的类型)的值。接下来循环开始,调用<em>collection</em>表达式的<code>next</code>方法。如果其返回值不是<code>None</code>,它将会被赋给<em>item</em>,然后执行<em>statements</em>,执行完毕后回到循环开始处;否则,将不会赋值给<em>item</em>也不会执行<em>statements</em><code>for-in</code>至此执行完毕。</p>
<blockquote>
<p>GRAMMAR OF A FOR-IN STATEMENT</p>
<p><em>for-in-statement</em><strong>for</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Patterns.html#//apple_ref/swift/grammar/pattern" target="_blank"><em>pattern</em></a> <strong>in</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Expressions.html#//apple_ref/swift/grammar/expression" target="_blank"><em>expression</em></a> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html#//apple_ref/swift/grammar/code-block" target="_blank"><em>code-block</em></a></p>
</blockquote>
<h3 id="while-">While 语句</h3>
<p><code>while</code>语句允许重复执行代码块。</p>
<p><code>while</code>语句的形式如下:</p>
<pre><code class="lang-swift">while `condition` {
`statements`
}
</code></pre>
<p><code>while</code>语句的执行流程如下:</p>
<ol>
<li><p>计算<em>condition</em>表达式:
如果为真(<code>true</code>)转到第2步。如果为假(<code>false</code>)<code>while</code>至此执行完毕。</p>
</li>
<li><p>执行<em>statements</em>然后转到第1步。</p>
</li>
</ol>
<p>由于<em>condition</em>的值在<em>statements</em>执行前就已计算出,因此<code>while</code>语句中的<em>statements</em>可能会被执行若干次,也可能不会被执行。</p>
<p><em>condition</em>表达式的值的类型必须符合<code>LogicValue</code>协议。同时,<em>condition</em>表达式也可以使用可选绑定,请参考<a href="">可选绑定<code>待添加链接</code></a></p>
<blockquote>
<p>GRAMMAR OF A WHILE STATEMENT</p>
<p><em>while-statement</em><strong>while</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/while-condition" target="_blank"><em>while-condition</em></a> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html#//apple_ref/swift/grammar/code-block" target="_blank"><em>code-block</em></a></p>
<p><em>while-condition</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Expressions.html#//apple_ref/swift/grammar/expression" target="_blank"><em>expression</em></a> | <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html#//apple_ref/swift/grammar/declaration" target="_blank"><em>declaration</em></a></p>
</blockquote>
<h3 id="do-while-">Do-While 语句</h3>
<p><code>do-while</code>语句允许代码块被执行一次或多次。</p>
<p><code>do-while</code>语句的形式如下:</p>
<pre><code class="lang-swift">do {
`statements`
} while `condition`
</code></pre>
<p><code>do-while</code>语句的执行流程如下:</p>
<ol>
<li><p>执行<em>statements</em>然后转到第2步。</p>
</li>
<li><p>计算<em>condition</em>表达式:
如果为真(<code>true</code>)转到第1步。如果为假(<code>false</code>)<code>do-while</code>至此执行完毕。</p>
</li>
</ol>
<p>由于<em>condition</em>表达式的值是在<em>statements</em>表达式执行后才计算出,因此<em>do-while</em>语句中的<em>statements</em>至少会被执行一次。</p>
<p><em>condition</em>表达式的值的类型必须符合<code>LogicValue</code>协议。同时,<em>condition</em>表达式也可以使用可选绑定,请参考<a href="">可选绑定<code>待添加链接</code></a></p>
<blockquote>
<p>GRAMMAR OF A DO-WHILE STATEMENT</p>
<p><em>do-while-statement</em><strong>do</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html#//apple_ref/swift/grammar/code-block" target="_blank"><em>code-block</em></a> <strong>while</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/while-condition" target="_blank"><em>while-condition</em></a> </p>
</blockquote>
<h2 id="-">分支语句</h2>
<p>取决于一个或者多个条件的值分支语句允许程序执行指定部分的代码。显然分支语句中条件的值将会决定如何分支以及执行哪一块代码。Swift 提供两种类型的分支语句:<code>if</code>语句和<code>switch</code>语句。</p>
<p><code>switch</code>语句中的控制流可以用<code>break</code>语句修改,请参考<a href="">Break 语句<code>待添加链接</code></a></p>
<blockquote>
<p>GRAMMAR OF A BRANCH STATEMENT</p>
<p><em>branch-statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/if-statement" target="_blank"><em>if-statement</em></a></p>
<p><em>branch-statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/switch-statement" target="_blank"><em>switch-statement</em></a></p>
</blockquote>
<h3 id="if-">If 语句</h3>
<p>取决于一个或多个条件的值,<code>if</code>语句将决定执行哪一块代码。</p>
<p><code>if</code>语句有两种标准形式,在这两种形式里都必须有大括号。</p>
<p>第一种形式是当且仅当条件为真时执行代码,像下面这样:</p>
<pre><code class="lang-swift">if `condition` {
`statements`
}
</code></pre>
<p>第二种形式是在第一种形式的基础上添加<em>else语句</em>,当只有一个<em>else语句</em>时,像下面这样:</p>
<pre><code class="lang-swift">if `condition` {
`statements to execute if condition is true`
} else {
`statements to execute if condition is false`
}
</code></pre>
<p>同时,<em>else语句</em>也可包含<code>if</code>语句,从而形成一条链来测试更多的条件,像下面这样:</p>
<pre><code class="lang-swift">if `condition 1` {
`statements to execute if condition 1 is true`
} else if `condition 2` {
`statements to execute if condition 2 is true`
}
else {
`statements to execute if both conditions are false`
}
</code></pre>
<p><code>if</code>语句中条件的值的类型必须符合<code>LogicValue</code>协议。同时,条件也可以使用可选绑定,请参考<a href="">可选绑定<code>待添加链接</code></a></p>
<blockquote>
<p>GRAMMAR OF AN IF STATEMENT</p>
<p><em>if-statement</em><strong>if</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/if-condition" target="_blank"><em>if-condition</em></a> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html#//apple_ref/swift/grammar/code-block" target="_blank"><em>code-block</em></a> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/else-clause" target="_blank"><em>else-clause</em></a> <em>opt</em></p>
<p><em>if-condition</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Expressions.html#//apple_ref/swift/grammar/expression" target="_blank"><em>expression</em></a> | <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html#//apple_ref/swift/grammar/declaration" target="_blank"><em>declaration</em></a></p>
<p><em>else-clause</em><strong>else</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html#//apple_ref/swift/grammar/code-block" target="_blank"><em>code-block</em></a> | <strong>else</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/if-statement" target="_blank"><em>if-statement</em></a> <em>opt</em></p>
</blockquote>
<h3 id="switch-">Switch 语句</h3>
<p>取决于<code>switch</code>语句的控制表达式(<em>control expression</em>)<code>switch</code>语句将决定执行哪一块代码。</p>
<p><code>switch</code>语句的形式如下:</p>
<pre><code class="lang-swift">switch `control expression` {
case `pattern 1`:
`statements`
case `pattern 2` where `condition`:
`statements`
case `pattern 3` where `condition`,
`pattern 4` where `condition`:
`statements`
default:
`statements`
}
</code></pre>
<p><code>switch</code>语句的<em>控制表达式(control expression)</em>会首先被计算,然后与每一个<em>case</em>的模式(pattern)进行匹配。如果匹配成功,程序将会执行对应的<em>case</em>块里的<em>statements</em>。另外,每一个<em>case</em>块都不能为空,也就是说在每一个<em>case</em>块中至少有一条语句。如果你不想在匹配到的<em>case</em>块中执行代码,只需在块里写一条<code>break</code>语句即可。</p>
<p>可以用作控制表达式的值是十分灵活的,除了标量类型(scalar types<code>Int</code><code>Character</code>)外,你可以使用任何类型的值,包括浮点数、字符串、元组、自定义类的实例和可选(optional)类型,甚至是枚举类型中的成员值和指定的范围(range)等。关于在<code>switch</code>语句中使用这些类型,请参考<a href="">控制流<code>待添加链接</code></a>一章的<a href="">Switch<code>待添加链接</code></a></p>
<p>你可以在模式后面添加一个起保护作用的表达式(guard expression)。<em>起保护作用的表达式</em>是这样构成的:关键字<code>where</code>后面跟着一个作为额外测试条件的表达式。因此,当且仅当<em>控制表达式</em>匹配一个<em>case</em>的某个模式且起保护作用的表达式为真时,对应<em>case</em>块中的<em>statements</em>才会被执行。在下面的例子中,<em>控制表达式</em>只会匹配含两个相等元素的元组,如<code>(1, 1)</code></p>
<pre><code class="lang-swift">case let (x, y) where x == y:
}
</code></pre>
<p>正如上面这个例子,也可以在模式中使用<code>let</code>(或<code>var</code>)语句来绑定常量(或变量)。这些常量(或变量)可以在其对应的起保护作用的表达式和其对应的<em>case</em>块里的代码中引用。但是,如果<em>case</em>中有多个模式匹配控制表达式,那么这些模式都不能绑定常量(或变量)。</p>
<p><code>switch</code>语句也可以包含默认(<code>default</code>)块,只有其它<em>case</em>块都无法匹配控制表达式时,默认块中的代码才会被执行。一个<code>switch</code>语句只能有一个默认块,而且必须在<code>switch</code>语句的最后面。</p>
<p>尽管模式匹配操作实际的执行顺序,特别是模式的计算顺序是不可知的,但是 Swift 规定<code>switch</code>语句中的模式匹配的顺序和书写源代码的顺序保持一致。因此,当多个模式含有相同的值且能够匹配控制表达式时,程序只会执行源代码中第一个匹配的<em>case</em>块中的代码。</p>
<h4 id="switch-">Switch 语句必须是完备的</h4>
<p>在 Swift 中,<code>switch</code>语句中控制表达式的每一个可能的值都必须至少有一个<code>case</code>块与之对应。在某些情况下(例如,表达式的类型是<code>Int</code>),你可以使用默认块满足该要求。</p>
<h4 id="-fall-through-">不存在隐式的贯穿(fall through)</h4>
<p>当匹配的<em>case</em>块中的代码执行完毕后,程序会终止<code>switch</code>语句,而不会继续执行下一个<em>case</em>块。这就意味着,如果你想执行下一个<em>case</em>块,需要显式地在你需要的<em>case</em>块里使用<code>fallthrough</code>语句。关于<code>fallthrough</code>语句的更多信息,请参考<a href="">Fallthrough 语句<code>待添加链接</code></a></p>
<blockquote>
<p>GRAMMAR OF A SWITCH STATEMENT</p>
<p><em>switch-statement</em><strong>switch</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Expressions.html#//apple_ref/swift/grammar/expression" target="_blank"><em>expression</em></a> <strong>{</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/switch-cases" target="_blank"><em>switch-cases</em></a> <em>opt</em> <strong>}</strong></p>
<p><em>switch-cases</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/switch-case" target="_blank"><em>switch-case</em></a> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/switch-cases" target="_blank"><em>switch-cases</em></a> <em>opt</em></p>
<p><em>switch-case</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/case-label" target="_blank"><em>case-label</em></a> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/statements" target="_blank"><em>statement</em></a> | <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/default-label" target="_blank"><em>default-label</em></a> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/statements" target="_blank"><em>statements</em></a></p>
<p><em>switch-case</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/case-label" target="_blank"><em>case-label</em></a> <strong>;</strong> | <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/default-label" target="_blank"><em>default-label</em></a> <strong>;</strong></p>
<p><em>case-label</em><strong>case</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/case-item-list" target="_blank"><em>case-item-list</em></a> <strong>:</strong></p>
<p><em>case-item-list</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Patterns.html#//apple_ref/swift/grammar/pattern" target="_blank"><em>pattern</em></a> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/guard-clause" target="_blank"><em>guard-clause</em></a> <em>opt</em> | <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Patterns.html#//apple_ref/swift/grammar/pattern" target="_blank"><em>pattern</em></a> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/guard-clause" target="_blank"><em>guard-clause</em></a> <em>opt</em>, <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/case-item-list" target="_blank"><em>case-item-list</em></a></p>
<p><em>default-label</em><strong>default :</strong></p>
<p><em>guard-clause</em><strong>where</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/guard-expression" target="_blank"><em>guard-expression</em></a></p>
<p><em>guard-expression</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Expressions.html#//apple_ref/swift/grammar/expression" target="_blank"><em>expression</em></a></p>
</blockquote>
<h2 id="-">带标签的语句</h2>
<p>你可以在循环语句或<code>switch</code>语句前面加上<em>标签</em>,它由标签名和紧随其后的冒号(:)组成。在<code>break</code><code>continue</code>后面跟上标签名可以显式地在循环语句或<code>switch</code>语句中更改控制流,把控制权传递给指定标签标记的语句。关于这两条语句用法,请参考<a href="">Break 语句<code>待添加链接</code></a><a href="">Continue 语句<code>待添加链接</code></a></p>
<p>标签的作用域是该标签所标记的语句之后的所有语句。你可以不使用带标签的语句,但只要使用它,标签名就必唯一。</p>
<p>关于使用带标签的语句的例子,请参考<a href="">控制流<code>待添加链接</code></a>一章的<a href="">带标签的语句<code>待添加链接</code></a></p>
<blockquote>
<p>GRAMMAR OF A LABELED STATEMENT</p>
<p><em>labeled-statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/statement-label" target="_blank"><em>statement-label</em></a> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/loop-statement" target="_blank"><em>loop-statement</em></a> | <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/statement-label" target="_blank"><em>statement-label</em></a> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/switch-statement" target="_blank"><em>switch-statement</em></a></p>
<p><em>statement-label</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/label-name" target="_blank"><em>label-name</em></a> <strong>:</strong></p>
<p><em>label-name</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/LexicalStructure.html#//apple_ref/swift/grammar/identifier" target="_blank"><em>identifier</em></a></p>
</blockquote>
<h2 id="-">控制传递语句</h2>
<p>通过无条件地把控制权从一片代码传递到另一片代码控制传递语句能够改变代码执行的顺序。Swift 提供四种类型的控制传递语句:<code>break</code>语句、<code>continue</code>语句、<code>fallthrough</code>语句和<code>return</code>语句。</p>
<blockquote>
<p>GRAMMAR OF A CONTROL TRANSER STATEMENT</p>
<p><em>control-transfer-statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/break-statement" target="_blank"><em>break-statement</em></a></p>
<p><em>control-transfer-statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/continue-statement" target="_blank"><em>continue-statement</em></a></p>
<p><em>control-transfer-statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/fallthrough-statement" target="_blank"><em>fallthrough-statement</em></a></p>
<p><em>control-transfer-statement</em><a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/return-statement" target="_blank"><em>return-statement</em></a></p>
</blockquote>
<h3 id="break-">Break 语句</h3>
<p><code>break</code>语句用于终止循环或<code>switch</code>语句的执行。使用<code>break</code>语句时,可以只写<code>break</code>这个关键词,也可以在<code>break</code>后面跟上标签名(label name),像下面这样:</p>
<pre><code class="lang-swift">break
break `label name`
</code></pre>
<p><code>break</code>语句后面带标签名时,可用于终止由这个标签标记的循环或<code>switch</code>语句的执行。</p>
<p>而当只写<code>break</code>时,则会终止<code>switch</code>语句或上下文中包含<code>break</code>语句的最内层循环的执行。</p>
<p>在这两种情况下,控制权都会被传递给循环或<code>switch</code>语句外面的第一行语句。</p>
<p>关于使用<code>break</code>语句的例子,请参考<a href="">控制流<code>待添加链接</code></a>一章的<a href="">Break<code>待添加链接</code></a><a href="">带标签的语句<code>待添加链接</code></a></p>
<blockquote>
<p>GRAMMAR OF A BREAK STATEMENT</p>
<p><em>break-statement</em><strong>break</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/label-name" target="_blank"><em>label-name</em></a> <em>opt</em></p>
</blockquote>
<h3 id="continue-">Continue 语句</h3>
<p><code>continue</code>语句用于终止循环中当前迭代的执行,但不会终止该循环的执行。使用<code>continue</code>语句时,可以只写<code>continue</code>这个关键词,也可以在<code>continue</code>后面跟上标签名(label name),像下面这样:</p>
<pre><code class="lang-swift">continue
continue `label name`
</code></pre>
<p><code>continue</code>语句后面带标签名时,可用于终止由这个标签标记的循环中当前迭代的执行。</p>
<p>而当只写<code>break</code>时,可用于终止上下文中包含<code>continue</code>语句的最内层循环中当前迭代的执行。</p>
<p>在这两种情况下,控制权都会被传递给循环外面的第一行语句。</p>
<p><code>for</code>语句中,<code>continue</code>语句执行后,<em>increment</em>表达式还是会被计算,这是因为每次循环体执行完毕后<em>increment</em>表达式都会被计算。</p>
<p>关于使用<code>continue</code>语句的例子,请参考<a href="">控制流<code>待添加链接</code></a>一章的<a href="">Continue<code>待添加链接</code></a><a href="">带标签的语句<code>待添加链接</code></a></p>
<blockquote>
<p>GRAMMAR OF A CONTINUE STATEMENT</p>
<p><em>continue-statement</em><strong>continue</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/label-name" target="_blank"><em>label-name</em></a> <em>opt</em></p>
</blockquote>
<h3 id="fallthrough-">Fallthrough 语句</h3>
<p><code>fallthrough</code>语句用于在<code>switch</code>语句中传递控制权。<code>fallthrough</code>语句会把控制权从<code>switch</code>语句中的一个<code>case</code>传递给下一个<code>case</code>。这种传递是无条件的,即使下一个<code>case</code>的值与<code>switch</code>语句的控制表达式的值不匹配。</p>
<p><code>fallthrough</code>语句可出现在<code>switch</code>语句中的任意<code>case</code>里,但不能出现在最后一个&#39;case&#39;块。同时,<code>fallthrough</code>语句也不能把控制权传递给使用了可选绑定的<code>case</code>块。</p>
<p>关于在<code>switch</code>语句中使用<code>fallthrough</code>语句的例子,请参考<a href="">控制流<code>待添加链接</code></a>一章的<a href="">控制传递语句<code>待添加链接</code></a></p>
<blockquote>
<p>GRAMMAR OF A FALLTRHOUGH STATEMENT</p>
<p><em>continue-statement</em><strong>fallthrough</strong></p>
</blockquote>
<h3 id="return-">Return 语句</h3>
<p><code>return</code>语句用于在函数或方法的实现中将控制权传递给调用者,接着程序将会从调用者的位置继续向下执行。</p>
<p>使用<code>return</code>语句时,可以只写<code>return</code>这个关键词,也可以在<code>return</code>后面跟上表达式,像下面这样:</p>
<pre><code class="lang-swift">return
return `表达式`
</code></pre>
<p><code>return</code>语句后面带表达式时表达式的值将会返回给调用者。如果表达式值的类型与调用者期望的类型不匹配Swift 则会在返回表达式的值之前将表达式值的类型转换为调用者期望的类型。</p>
<p>而当只写<code>return</code>时,仅仅是将控制权从该函数或方法传递给调用者,而不返回一个值。(这就是说,该函数或方法的返回类型为<code>Void</code><code>()</code></p>
<blockquote>
<p>GRAMMAR OF A RETURN STATEMENT</p>
<p><em>return-statement</em><strong>return</strong> <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Expressions.html#//apple_ref/swift/grammar/expression" target="_blank"><em>expression</em></a> <em>opt</em></p>
</blockquote>
</section>
</div> </div>
</div> </div>
</div> </div>

View File

@ -46,7 +46,7 @@
<div class="book" data-level="3" data-basepath=".." data-revision="1402287112409"> <div class="book" data-level="3" data-basepath=".." data-revision="1402299637539">
<div class="book-header"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <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"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="../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> </a>
@ -268,7 +268,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="../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> </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/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> <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/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> <a href="../chapter2/20_Extensions.html" title="扩展" class="chapter done " data-progress="2.20" style="left: 44.73684210526316%;"></a>

View File

@ -44,7 +44,7 @@
<div class="book" data-level="0" data-basepath="." data-revision="1402287112409"> <div class="book" data-level="0" data-basepath="." data-revision="1402299637539">
<div class="book-header"> <div class="book-header">
<!-- Actions Left --> <!-- Actions Left -->
<a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a> <a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
@ -176,7 +176,7 @@
<li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html"> <li class="chapter " data-level="2.2" data-path="chapter2/02_Basic_Operators.html">
<a href="./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> </a>
@ -266,7 +266,7 @@
<li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html"> <li class="chapter " data-level="2.12" data-path="chapter2/12_Subscripts.html">
<a href="./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> </a>
@ -518,7 +518,7 @@
<a href="./chapter2/11_Methods.html" title="方法" class="chapter " data-progress="2.11" style="left: 18.42105263157895%;"></a> <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> <a href="./chapter2/13_Inheritance.html" title="继承" class="chapter " data-progress="2.13" style="left: 23.68421052631579%;"></a>
@ -534,7 +534,7 @@
<a href="./chapter2/19_Nested_Types.html" title="嵌套类型" class="chapter " data-progress="2.19" style="left: 39.473684210526315%;"></a> <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> <a href="./chapter2/20_Extensions.html" title="扩展" class="chapter " data-progress="2.20" style="left: 44.73684210526316%;"></a>
@ -585,7 +585,7 @@
<div class="page-inner"> <div class="page-inner">
<section class="normal" id="section-gitbook_35"> <section class="normal" id="section-gitbook_3">
<h1 id="swift-">Swift 编程语言</h1> <h1 id="swift-">Swift 编程语言</h1>
<p>Swift 是苹果在 WWDC 2014 上发布的一款全新的编程语言,本书译自苹果官方的 Swift 教程《The Swift Programming Language》。</p> <p>Swift 是苹果在 WWDC 2014 上发布的一款全新的编程语言,本书译自苹果官方的 Swift 教程《The Swift Programming Language》。</p>

View File

@ -1,5 +1,5 @@
CACHE MANIFEST CACHE MANIFEST
# Revision 1402287112410 # Revision 1402299637540
CACHE: CACHE:
index.html index.html

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
* [Swift 初见](chapter1/02_a_swift_tour.md) * [Swift 初见](chapter1/02_a_swift_tour.md)
* [Swift 教程](chapter2/chapter2.md) * [Swift 教程](chapter2/chapter2.md)
* [基础部分](chapter2/01_The_Basics.md) * [基础部分](chapter2/01_The_Basics.md)
* [基本操作](chapter2/02_Basic_Operators.md) * [基本运算](chapter2/02_Basic_Operators.md)
* [字符串和字符](chapter2/03_Strings_and_Characters.md) * [字符串和字符](chapter2/03_Strings_and_Characters.md)
* [集合类型](chapter2/04_Collection_Types.md) * [集合类型](chapter2/04_Collection_Types.md)
* [控制流](chapter2/05_Control_Flow.md) * [控制流](chapter2/05_Control_Flow.md)
@ -15,7 +15,7 @@
* [类和结构体](chapter2/09_Classes_and_Structures.md) * [类和结构体](chapter2/09_Classes_and_Structures.md)
* [属性](chapter2/10_Properties.md) * [属性](chapter2/10_Properties.md)
* [方法](chapter2/11_Methods.md) * [方法](chapter2/11_Methods.md)
* [下标](chapter2/12_Subscripts.md) * [附属脚本](chapter2/12_Subscripts.md)
* [继承](chapter2/13_Inheritance.md) * [继承](chapter2/13_Inheritance.md)
* [构造过程](chapter2/14_Initialization.md) * [构造过程](chapter2/14_Initialization.md)
* [析构过程](chapter2/15_Deinitialization.md) * [析构过程](chapter2/15_Deinitialization.md)