update underscore
This commit is contained in:
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="1.1" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="1.1" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -590,6 +590,7 @@
|
|||||||
<section class="normal" id="section-gitbook_4">
|
<section class="normal" id="section-gitbook_4">
|
||||||
|
|
||||||
<h1 id="-swift">关于 Swift</h1>
|
<h1 id="-swift">关于 Swift</h1>
|
||||||
|
<hr>
|
||||||
<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>
|
||||||
<p>Swift 的开发从很久之前就开始了。为了给 Swift 打好基础,苹果公司改进了编译器,调试器和框架结构。我们使用自动引用计数(Automatic Reference Counting, ARC)来简化内存管理。我们在 Foundation 和 Cocoa的基础上构建框架栈并将其标准化。Objective-C 本身支持块、集合语法和模块,所以框架可以轻松支持现代编程语言技术。得益于这些基础工作,我们现在可以发布一个新语言,用于未来的苹果软件的开发。</p>
|
<p>Swift 的开发从很久之前就开始了。为了给 Swift 打好基础,苹果公司改进了编译器,调试器和框架结构。我们使用自动引用计数(Automatic Reference Counting, ARC)来简化内存管理。我们在 Foundation 和 Cocoa的基础上构建框架栈并将其标准化。Objective-C 本身支持块、集合语法和模块,所以框架可以轻松支持现代编程语言技术。得益于这些基础工作,我们现在可以发布一个新语言,用于未来的苹果软件的开发。</p>
|
||||||
<p>Objective-C 开发者对于 Swift 并不会感到陌生。它采用了 Objective-C 的命名参数以及动态对象模型,可以无缝对接到现有的 Cocoa 框架,并且可以兼容 Objective-C 代码。在此基础之上,Swift 还有许多新特性并且支持过程式编程和面向对象编程。</p>
|
<p>Objective-C 开发者对于 Swift 并不会感到陌生。它采用了 Objective-C 的命名参数以及动态对象模型,可以无缝对接到现有的 Cocoa 框架,并且可以兼容 Objective-C 代码。在此基础之上,Swift 还有许多新特性并且支持过程式编程和面向对象编程。</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="1.2" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="1.2" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_5">
|
<section class="normal" id="section-gitbook_6">
|
||||||
|
|
||||||
<h1 id="swift-">Swift 初见</h1>
|
<h1 id="swift-">Swift 初见</h1>
|
||||||
|
<hr>
|
||||||
<p>本页内容包括:</p>
|
<p>本页内容包括:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>简单值</li>
|
<li>简单值</li>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="1" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="1" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,7 +587,7 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_6">
|
<section class="normal" id="section-gitbook_8">
|
||||||
|
|
||||||
<h1 id="-swift">欢迎使用 Swift</h1>
|
<h1 id="-swift">欢迎使用 Swift</h1>
|
||||||
<p>在本章中您将了解 Swift 的特性和开发历史,并对 Swift 有一个初步的了解。</p>
|
<p>在本章中您将了解 Swift 的特性和开发历史,并对 Swift 有一个初步的了解。</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.1" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.1" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_8">
|
<section class="normal" id="section-gitbook_11">
|
||||||
|
|
||||||
<h1 id="-">基础部分</h1>
|
<h1 id="-">基础部分</h1>
|
||||||
|
<hr>
|
||||||
<p>Swift 是 iOS 和 OS X 应用开发的一门新语言。然而,如果你有 C 或者 Objective-C 开发经验的话,你会发现 Swift 的很多内容都是你熟悉的。</p>
|
<p>Swift 是 iOS 和 OS X 应用开发的一门新语言。然而,如果你有 C 或者 Objective-C 开发经验的话,你会发现 Swift 的很多内容都是你熟悉的。</p>
|
||||||
<p>Swift 的类型是在 C 和 Objective-C 的基础上提出的,<code>Int</code>是整型;<code>Double</code>和<code>Float</code>是浮点型;<code>Bool</code>是布尔型;<code>String</code>是字符串。Swift 还有两个有用的集合类型,<code>Array</code>和<code>Dictionary</code>,详情参见<code>集合类型(待添加链接)</code>。</p>
|
<p>Swift 的类型是在 C 和 Objective-C 的基础上提出的,<code>Int</code>是整型;<code>Double</code>和<code>Float</code>是浮点型;<code>Bool</code>是布尔型;<code>String</code>是字符串。Swift 还有两个有用的集合类型,<code>Array</code>和<code>Dictionary</code>,详情参见<code>集合类型(待添加链接)</code>。</p>
|
||||||
<p>就像 C 语言一样,Swift 使用变量来进行存储并通过变量名来关联值。在 Swift 中,值不可变的变量有着广泛的应用,它们就是常量,而且比 C 语言的常量更强大。在 Swift 中,如果你要处理的值不需要改变,那使用常量可以让你的代码更加安全并且更好地表达你的意图。</p>
|
<p>就像 C 语言一样,Swift 使用变量来进行存储并通过变量名来关联值。在 Swift 中,值不可变的变量有着广泛的应用,它们就是常量,而且比 C 语言的常量更强大。在 Swift 中,如果你要处理的值不需要改变,那使用常量可以让你的代码更加安全并且更好地表达你的意图。</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.2" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.2" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_36">
|
<section class="normal" id="section-gitbook_46">
|
||||||
|
|
||||||
<h1 id="-">基本运算符</h1>
|
<h1 id="-">基本运算符</h1>
|
||||||
|
<hr>
|
||||||
<p>运算符是检查, 改变, 合并值的特殊符号或短语. 例如, 加号 <code>+</code> 把计算两个数的和(如 <code>let i = 1 + 2</code>). 复杂些的运行算包括逻辑与<code>&&</code>(如 <code>if enteredDoorCode && passedRetinaScan</code>), 还有自增运算符 <code>++i</code> 这样让自身加一的便捷运算.</p>
|
<p>运算符是检查, 改变, 合并值的特殊符号或短语. 例如, 加号 <code>+</code> 把计算两个数的和(如 <code>let i = 1 + 2</code>). 复杂些的运行算包括逻辑与<code>&&</code>(如 <code>if enteredDoorCode && passedRetinaScan</code>), 还有自增运算符 <code>++i</code> 这样让自身加一的便捷运算.</p>
|
||||||
<p>Swift支持大部分标准C语言的运算符, 且改进许多特性来减少常规编码错误. 如, 赋值符 <code>=</code> 不返回值, 以防止错把等号 <code>==</code> 写成赋值号 <code>=</code> 而导致Bug. 数值运算符( <code>+</code> , <code>-</code>, <code>*</code>, <code>/</code>, <code>%</code>等)会检测并不允许值溢出, 以此来避免保存变量时由于变量大于或小于其类型所能承载的范围时导致的异常结果. 当然允许你选择使用Swift的溢出运算符来玩溢出. 具体使用请移步<a href="Overflow Operators">溢出运算符</a>.</p>
|
<p>Swift支持大部分标准C语言的运算符, 且改进许多特性来减少常规编码错误. 如, 赋值符 <code>=</code> 不返回值, 以防止错把等号 <code>==</code> 写成赋值号 <code>=</code> 而导致Bug. 数值运算符( <code>+</code> , <code>-</code>, <code>*</code>, <code>/</code>, <code>%</code>等)会检测并不允许值溢出, 以此来避免保存变量时由于变量大于或小于其类型所能承载的范围时导致的异常结果. 当然允许你选择使用Swift的溢出运算符来玩溢出. 具体使用请移步<a href="Overflow Operators">溢出运算符</a>.</p>
|
||||||
<p>区别于C语言, 在Swift中你可以对浮点数进行取余运算( <code>%</code> ), 还提供了C语言没有的表达两数之间的值的区间运算符, ( <code>a..b</code> 和 <code>a...b</code> ), 这方便我们表达一个区间内的数值.</p>
|
<p>区别于C语言, 在Swift中你可以对浮点数进行取余运算( <code>%</code> ), 还提供了C语言没有的表达两数之间的值的区间运算符, ( <code>a..b</code> 和 <code>a...b</code> ), 这方便我们表达一个区间内的数值.</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.3" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.3" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,7 +587,7 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_9">
|
<section class="normal" id="section-gitbook_13">
|
||||||
|
|
||||||
<h1 id="-strings-and-characters-">字符串和字符 (Strings and Characters)</h1>
|
<h1 id="-strings-and-characters-">字符串和字符 (Strings and Characters)</h1>
|
||||||
<hr>
|
<hr>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.4" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.4" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_21">
|
<section class="normal" id="section-gitbook_25">
|
||||||
|
|
||||||
<h1 id="-collection-types-">集合类型 (Collection Types)</h1>
|
<h1 id="-collection-types-">集合类型 (Collection Types)</h1>
|
||||||
|
<hr>
|
||||||
<p>Swift语言提供经典的数组和字典两种集合类型来存储集合数据。数组用来按顺序存储相同类型的数据。字典虽然无序存储相同类型数据值但是需要由独有的标识符引用和寻址(就是键值对)。</p>
|
<p>Swift语言提供经典的数组和字典两种集合类型来存储集合数据。数组用来按顺序存储相同类型的数据。字典虽然无序存储相同类型数据值但是需要由独有的标识符引用和寻址(就是键值对)。</p>
|
||||||
<p>Swift语言里的数组和字典中存储的数据值类型必须明确。 这意味着我们不能把不正确的数据类型插入其中。 同时这也说明我们完全可以对获取出的值类型非常自信。 Swift对显式类型集合的使用确保了我们的代码对工作所需要的类型非常清楚,也让我们在开发中可以早早地找到任何的类型不匹配错误。</p>
|
<p>Swift语言里的数组和字典中存储的数据值类型必须明确。 这意味着我们不能把不正确的数据类型插入其中。 同时这也说明我们完全可以对获取出的值类型非常自信。 Swift对显式类型集合的使用确保了我们的代码对工作所需要的类型非常清楚,也让我们在开发中可以早早地找到任何的类型不匹配错误。</p>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.5" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.5" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_22">
|
<section class="normal" id="section-gitbook_27">
|
||||||
|
|
||||||
<h1 id="-">控制流</h1>
|
<h1 id="-">控制流</h1>
|
||||||
|
<hr>
|
||||||
<p>Swift提供了类似C语言的流程控制结构,包括可以多次执行任务的<code>for</code>和<code>while</code>循环,基于特定条件选择执行不同代码分支的<code>if</code>和<code>switch</code>语句,还有控制流程跳转到其他代码的<code>break</code>和<code>continue</code>语句。</p>
|
<p>Swift提供了类似C语言的流程控制结构,包括可以多次执行任务的<code>for</code>和<code>while</code>循环,基于特定条件选择执行不同代码分支的<code>if</code>和<code>switch</code>语句,还有控制流程跳转到其他代码的<code>break</code>和<code>continue</code>语句。</p>
|
||||||
<p>除了C里面传统的 <code>for</code> 条件递增循环,Swift 还增加了 <code>for-in</code> 循环,用来更简单地遍历数组(array),字典(dictionary),范围(range),字符串(string)和其他序列类型。</p>
|
<p>除了C里面传统的 <code>for</code> 条件递增循环,Swift 还增加了 <code>for-in</code> 循环,用来更简单地遍历数组(array),字典(dictionary),范围(range),字符串(string)和其他序列类型。</p>
|
||||||
<p>Swift 的 <code>switch</code> 语句比 C 语言中更加强大。在 C 语言中,如果某个 case 不小心漏写了 <code>break</code>,这个 case 就会“掉入”下一个 case,Swift 无需写 <code>break</code>,所以不会发生这种“掉入”的情况。Case 还可以匹配更多的类型模式,包括范围(range)匹配,元组(tuple)和特定类型的描述。<code>switch</code> case 语句中匹配的值可以是由 case 体内部临时的常量或者变量决定,也可以由 <code>where</code> 分句描述更复杂的匹配条件。</p>
|
<p>Swift 的 <code>switch</code> 语句比 C 语言中更加强大。在 C 语言中,如果某个 case 不小心漏写了 <code>break</code>,这个 case 就会“掉入”下一个 case,Swift 无需写 <code>break</code>,所以不会发生这种“掉入”的情况。Case 还可以匹配更多的类型模式,包括范围(range)匹配,元组(tuple)和特定类型的描述。<code>switch</code> case 语句中匹配的值可以是由 case 体内部临时的常量或者变量决定,也可以由 <code>where</code> 分句描述更复杂的匹配条件。</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.6" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.6" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_23">
|
<section class="normal" id="section-gitbook_29">
|
||||||
|
|
||||||
<h1 id="-functions-">函数(Functions)</h1>
|
<h1 id="-functions-">函数(Functions)</h1>
|
||||||
|
<hr>
|
||||||
<p>本页包含内容:</p>
|
<p>本页包含内容:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>函数定义与调用</li>
|
<li>函数定义与调用</li>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.7" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.7" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,7 +587,7 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_24">
|
<section class="normal" id="section-gitbook_31">
|
||||||
|
|
||||||
<h1 id="-">闭包</h1>
|
<h1 id="-">闭包</h1>
|
||||||
<hr>
|
<hr>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.8" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.8" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_30">
|
<section class="normal" id="section-gitbook_37">
|
||||||
|
|
||||||
<h1 id="-">枚举</h1>
|
<h1 id="-">枚举</h1>
|
||||||
|
<hr>
|
||||||
<p>本页内容包含:</p>
|
<p>本页内容包含:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>枚举语法</li>
|
<li>枚举语法</li>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.9" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.9" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,7 +587,7 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_31">
|
<section class="normal" id="section-gitbook_39">
|
||||||
|
|
||||||
<h3 id="-">类和结构体</h3>
|
<h3 id="-">类和结构体</h3>
|
||||||
<p>本页包含内容:</p>
|
<p>本页包含内容:</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.10" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.10" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,7 +587,7 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_32">
|
<section class="normal" id="section-gitbook_40">
|
||||||
|
|
||||||
<h1 id="-properties-">属性 (Properties)</h1>
|
<h1 id="-properties-">属性 (Properties)</h1>
|
||||||
<hr>
|
<hr>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.11" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.11" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_34">
|
<section class="normal" id="section-gitbook_42">
|
||||||
|
|
||||||
<h1 id="-methods-">方法(Methods)</h1>
|
<h1 id="-methods-">方法(Methods)</h1>
|
||||||
|
<hr>
|
||||||
<p><strong>方法</strong>是与某些特定类型相关联的函数。类、结构体、枚举都可以定义实例方法;实例方法为给定类型的实例封装了具体的任务与功能。类、结构体、枚举也可以定义类型方法;类型方法与类型自身相关联。类型方法与Objective-C中的类方法(class methods)相似。</p>
|
<p><strong>方法</strong>是与某些特定类型相关联的函数。类、结构体、枚举都可以定义实例方法;实例方法为给定类型的实例封装了具体的任务与功能。类、结构体、枚举也可以定义类型方法;类型方法与类型自身相关联。类型方法与Objective-C中的类方法(class methods)相似。</p>
|
||||||
<p>在Swift中,结构体和枚举能够定义方法;事实上这是Swift与C/Objective-C的主要区别之一。在Objective-C中,类是唯一能定义方法的类型。但在Swift中,你不仅能选择是否要定义一个类/结构体/枚举,还能灵活的在你创建的类型(类/结构体/枚举)上定义方法。</p>
|
<p>在Swift中,结构体和枚举能够定义方法;事实上这是Swift与C/Objective-C的主要区别之一。在Objective-C中,类是唯一能定义方法的类型。但在Swift中,你不仅能选择是否要定义一个类/结构体/枚举,还能灵活的在你创建的类型(类/结构体/枚举)上定义方法。</p>
|
||||||
<h3 id="-instance-methods-">实例方法(Instance Methods)</h3>
|
<h3 id="-instance-methods-">实例方法(Instance Methods)</h3>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.12" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.12" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_35">
|
<section class="normal" id="section-gitbook_44">
|
||||||
|
|
||||||
<h1 id="-subscripts-">下标 (Subscripts)</h1>
|
<h1 id="-subscripts-">下标(Subscripts)</h1>
|
||||||
|
<hr>
|
||||||
<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>
|
||||||
<p>对于同一个目标可以定义多个下标,通过索引值类型的不同来进行重载,而且索引值的个数可以是多个。</p>
|
<p>对于同一个目标可以定义多个下标,通过索引值类型的不同来进行重载,而且索引值的个数可以是多个。</p>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.13" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.13" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_7">
|
<section class="normal" id="section-gitbook_9">
|
||||||
|
|
||||||
<h1 id="-">继承</h1>
|
<h1 id="-">继承</h1>
|
||||||
|
<hr>
|
||||||
<p>一个类可以继承另一个类的方法,属性和其它特性。当一个类继承其它类,继承类叫子类,被继承类叫超类(或父类)。在Swift中,继承是区分「类」与其它类型的一个基本特征。</p>
|
<p>一个类可以继承另一个类的方法,属性和其它特性。当一个类继承其它类,继承类叫子类,被继承类叫超类(或父类)。在Swift中,继承是区分「类」与其它类型的一个基本特征。</p>
|
||||||
<p>在Swift中,类可以调用和访问超类的方法,属性和下标,并且可以重写(override)这些方法,属性和下标来优化或修改它们的行为。Swift会检查你的重写定义在超类中是否有匹配的定义,以此确保你的重写行为是正确的。</p>
|
<p>在Swift中,类可以调用和访问超类的方法,属性和下标,并且可以重写(override)这些方法,属性和下标来优化或修改它们的行为。Swift会检查你的重写定义在超类中是否有匹配的定义,以此确保你的重写行为是正确的。</p>
|
||||||
<p>可以为类中继承来的属性添加属性观察器(property observer),这样一来,当属性值改变时,类就会被通知到。可以为任何属性添加属性观察器,无论它原本被定义为存储型属性(stored property)还是计算型属性(computed property)。</p>
|
<p>可以为类中继承来的属性添加属性观察器(property observer),这样一来,当属性值改变时,类就会被通知到。可以为任何属性添加属性观察器,无论它原本被定义为存储型属性(stored property)还是计算型属性(computed property)。</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.14" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.14" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.15" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.15" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_38">
|
<section class="normal" id="section-gitbook_49">
|
||||||
|
|
||||||
<h1 id="-">析构过程</h1>
|
<h1 id="-">析构过程</h1>
|
||||||
|
<hr>
|
||||||
<p>在一个类的实例被释放之前,析构函数被立即调用。用关键字deinit来标示析构函数,类似于初始化函数用init来标示。析构函数只适用于类类型。</p>
|
<p>在一个类的实例被释放之前,析构函数被立即调用。用关键字deinit来标示析构函数,类似于初始化函数用init来标示。析构函数只适用于类类型。</p>
|
||||||
<h2 id="-">析构过程原理</h2>
|
<h2 id="-">析构过程原理</h2>
|
||||||
<p>Swift会自动释放不再需要的实例以释放资源。如自动引用计数那一章描述,Swift通过自动引用计数(ARC)处理实例的内存管理。通常当你的实例被释放时不需要手动的去清理。但是,当使用自己的资源时,你可能需要进行一些额外的清理。例如,如果创建了一个自定义的类来打开一个文件,并写入一些数据,你可能需要在类实例被释放之前关闭该文件。</p>
|
<p>Swift会自动释放不再需要的实例以释放资源。如自动引用计数那一章描述,Swift通过自动引用计数(ARC)处理实例的内存管理。通常当你的实例被释放时不需要手动的去清理。但是,当使用自己的资源时,你可能需要进行一些额外的清理。例如,如果创建了一个自定义的类来打开一个文件,并写入一些数据,你可能需要在类实例被释放之前关闭该文件。</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.16" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.16" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_39">
|
<section class="normal" id="section-gitbook_51">
|
||||||
|
|
||||||
<h1 id="-">自动引用计数</h1>
|
<h1 id="-">自动引用计数</h1>
|
||||||
|
<hr>
|
||||||
<p>本页包含内容:</p>
|
<p>本页包含内容:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>自动引用计数的工作机制</li>
|
<li>自动引用计数的工作机制</li>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.17" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.17" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_40">
|
<section class="normal" id="section-gitbook_53">
|
||||||
|
|
||||||
<h1 id="optional-chaining">Optional Chaining</h1>
|
<h1 id="optional-chaining">Optional Chaining</h1>
|
||||||
|
<hr>
|
||||||
<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>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p>笔记:
|
<p>笔记:
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.18" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.18" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_42">
|
<section class="normal" id="section-gitbook_55">
|
||||||
|
|
||||||
<h1 id="-type-casting-">类型检查(Type Casting)</h1>
|
<h1 id="-type-casting-">类型检查(Type Casting)</h1>
|
||||||
|
<hr>
|
||||||
<p>(ps:为了方便各位检验所以保留了英文,可删。)
|
<p>(ps:为了方便各位检验所以保留了英文,可删。)
|
||||||
<em>类型检查</em>是一种检查类实例的方式,并且哦或者也是让实例作为它的父类或者子类的一种方式。</p>
|
<em>类型检查</em>是一种检查类实例的方式,并且哦或者也是让实例作为它的父类或者子类的一种方式。</p>
|
||||||
<p> <em>Type casting</em> is a way to check the type of an instance, and/or to treat that instance as if it is a different superclass or subclass from somewhere else in its own class hierarchy.</p>
|
<p> <em>Type casting</em> is a way to check the type of an instance, and/or to treat that instance as if it is a different superclass or subclass from somewhere else in its own class hierarchy.</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.19" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.19" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_41">
|
<section class="normal" id="section-gitbook_57">
|
||||||
|
|
||||||
<h1 id="-">类型嵌套</h1>
|
<h1 id="-">类型嵌套</h1>
|
||||||
|
<hr>
|
||||||
<p>本页包含内容:</p>
|
<p>本页包含内容:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>类型嵌套实例</li>
|
<li>类型嵌套实例</li>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.20" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.20" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,7 +587,7 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_43">
|
<section class="normal" id="section-gitbook_59">
|
||||||
|
|
||||||
<h1 id="-extensions-">扩展(Extensions)</h1>
|
<h1 id="-extensions-">扩展(Extensions)</h1>
|
||||||
<hr>
|
<hr>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.21" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.21" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_45">
|
<section class="normal" id="section-gitbook_64">
|
||||||
|
|
||||||
<h1 id="-">协议</h1>
|
<h1 id="-">协议</h1>
|
||||||
|
<hr>
|
||||||
<p><code>Protocol(协议)</code>用于<strong>统一</strong>方法和属性的名称,而不实现任何功能,(<em>译者注: 协议在其他语言中也称作<code>接口(Interface)</code></em>).<code>协议</code>能够被<code>类</code>,<code>枚举</code>,<code>结构体</code>实现,满足协议要求的<code>类</code>,<code>枚举</code>,<code>结构体</code>被称为协议的<code>遵循者</code>.</p>
|
<p><code>Protocol(协议)</code>用于<strong>统一</strong>方法和属性的名称,而不实现任何功能,(<em>译者注: 协议在其他语言中也称作<code>接口(Interface)</code></em>).<code>协议</code>能够被<code>类</code>,<code>枚举</code>,<code>结构体</code>实现,满足协议要求的<code>类</code>,<code>枚举</code>,<code>结构体</code>被称为协议的<code>遵循者</code>.</p>
|
||||||
<p><code>遵循者</code>需要提供<code>协议</code>指定的成员,如<code>属性</code>,<code>方法</code>,<code>操作符</code>,<code>下标</code>等.</p>
|
<p><code>遵循者</code>需要提供<code>协议</code>指定的成员,如<code>属性</code>,<code>方法</code>,<code>操作符</code>,<code>下标</code>等.</p>
|
||||||
<h2 id="-">协议的语法</h2>
|
<h2 id="-">协议的语法</h2>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.22" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.22" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,7 +587,7 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_46">
|
<section class="normal" id="section-gitbook_61">
|
||||||
|
|
||||||
<h1 id="-">泛型</h1>
|
<h1 id="-">泛型</h1>
|
||||||
<hr>
|
<hr>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.23" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2.23" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,7 +587,7 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_49">
|
<section class="normal" id="section-gitbook_66">
|
||||||
|
|
||||||
<p>In addition to the operators described in <a href="Basic Operators">Basic Operators</a>, Swift provides several advanced operators that perform more complex value manipulation. These include all of the bitwise and bit shifting operators you will be familiar with from C and Objective-C.</p>
|
<p>In addition to the operators described in <a href="Basic Operators">Basic Operators</a>, Swift provides several advanced operators that perform more complex value manipulation. These include all of the bitwise and bit shifting operators you will be familiar with from C and Objective-C.</p>
|
||||||
<p>除于<a href="Basic Operators">基本操作符</a>中所讲的运算符, Swift还有许多复杂的高级运算符, 包括了C语和Objective-C中的位运算符和位移运算.</p>
|
<p>除于<a href="Basic Operators">基本操作符</a>中所讲的运算符, Swift还有许多复杂的高级运算符, 包括了C语和Objective-C中的位运算符和位移运算.</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="2" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,7 +587,7 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_50">
|
<section class="normal" id="section-gitbook_67">
|
||||||
|
|
||||||
<h1 id="swift-">Swift 教程</h1>
|
<h1 id="swift-">Swift 教程</h1>
|
||||||
<p>本章介绍了 Swift 的各种特性及其使用方法,是全书的核心部分。</p>
|
<p>本章介绍了 Swift 的各种特性及其使用方法,是全书的核心部分。</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="3.1" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="3.1" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_52">
|
<section class="normal" id="section-gitbook_70">
|
||||||
|
|
||||||
<h1 id="-">关于语言附注</h1>
|
<h1 id="-">关于语言附注</h1>
|
||||||
|
<hr>
|
||||||
<p>本书的这一节描述了Swift编程语言的形式语法。这里描述的语法是为了帮助您更详细的了解该语言,而不是让您直接实现一个解析器或编译器。</p>
|
<p>本书的这一节描述了Swift编程语言的形式语法。这里描述的语法是为了帮助您更详细的了解该语言,而不是让您直接实现一个解析器或编译器。</p>
|
||||||
<p>Swift语言相对小点,这是由于在Swift代码中几乎无处不在的许多常见的的类型,函数以及运算符都由Swift标准库来定义。虽然这些类型,函数和运算符不是Swift语言本身的一部分,但是它们被广泛用于这本书的讨论和代码范例。</p>
|
<p>Swift语言相对小点,这是由于在Swift代码中几乎无处不在的许多常见的的类型,函数以及运算符都由Swift标准库来定义。虽然这些类型,函数和运算符不是Swift语言本身的一部分,但是它们被广泛用于这本书的讨论和代码范例。</p>
|
||||||
<h1 id="-">如何阅读语法</h1>
|
<h1 id="-">如何阅读语法</h1>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="3.2" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="3.2" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_58">
|
<section class="normal" id="section-gitbook_77">
|
||||||
|
|
||||||
<h1 id="-">语法结构</h1>
|
<h1 id="-">语法结构</h1>
|
||||||
|
<hr>
|
||||||
<p>本页包含内容:</p>
|
<p>本页包含内容:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>空白与注释(<em>Whitespace and Comments</em>)</li>
|
<li>空白与注释(<em>Whitespace and Comments</em>)</li>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="3.3" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="3.3" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,7 +587,7 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_53">
|
<section class="normal" id="section-gitbook_72">
|
||||||
|
|
||||||
<h1 id="-types-">类型(Types)</h1>
|
<h1 id="-types-">类型(Types)</h1>
|
||||||
<hr>
|
<hr>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="3.4" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="3.4" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -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_74">
|
||||||
|
|
||||||
<h1 id="-expressions-">表达式(Expressions)</h1>
|
<h1 id="-expressions-">表达式(Expressions)</h1>
|
||||||
<hr>
|
<hr>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="3.6" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="3.6" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="3.7" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="3.7" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_51">
|
<section class="normal" id="section-gitbook_68">
|
||||||
|
|
||||||
<h1 id="-">特性</h1>
|
<h1 id="-">特性</h1>
|
||||||
|
<hr>
|
||||||
<p>特性提供了关于声明和类型的更多信息。在Swift中有两类特性,用于修饰声明的以及用于修饰类型的。例如,<code>required</code>特性,当应用于一个类的指定或便利初始化器声明时,表明它的每个子类都必须实现那个初始化器。再比如<code>noreturn</code>特性,当应用于函数或方法类型时,表明该函数或方法不会返回到它的调用者。</p>
|
<p>特性提供了关于声明和类型的更多信息。在Swift中有两类特性,用于修饰声明的以及用于修饰类型的。例如,<code>required</code>特性,当应用于一个类的指定或便利初始化器声明时,表明它的每个子类都必须实现那个初始化器。再比如<code>noreturn</code>特性,当应用于函数或方法类型时,表明该函数或方法不会返回到它的调用者。</p>
|
||||||
<p>通过以下方式指定一个特性:符号<code>@</code>后面跟特性名,如果包含参数,则把参数带上:</p>
|
<p>通过以下方式指定一个特性:符号<code>@</code>后面跟特性名,如果包含参数,则把参数带上:</p>
|
||||||
<pre><code>@attribute name
|
<pre><code>@attribute name
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="3.8" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="3.8" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_59">
|
<section class="normal" id="section-gitbook_79">
|
||||||
|
|
||||||
<h1 id="-patterns-">模式(Patterns)</h1>
|
<h1 id="-patterns-">模式(Patterns)</h1>
|
||||||
|
<hr>
|
||||||
<p>模式(pattern)代表了单个值或者复合值的结构。例如,元组<code>(1, 2)</code>的结构是逗号分隔的,包含两个元素的列表。因为模式代表一种值的结构,而不是特定的某个值,你可以把模式和各种同类型的值匹配起来。比如,<code>(x, y)</code>可以匹配元组<code>(1, 2)</code>,以及任何含两个元素的元组。除了将模式与一个值匹配外,你可以从合成值中提取出部分或全部,然后分别把各个部分和一个常量或变量绑定起来。</p>
|
<p>模式(pattern)代表了单个值或者复合值的结构。例如,元组<code>(1, 2)</code>的结构是逗号分隔的,包含两个元素的列表。因为模式代表一种值的结构,而不是特定的某个值,你可以把模式和各种同类型的值匹配起来。比如,<code>(x, y)</code>可以匹配元组<code>(1, 2)</code>,以及任何含两个元素的元组。除了将模式与一个值匹配外,你可以从合成值中提取出部分或全部,然后分别把各个部分和一个常量或变量绑定起来。</p>
|
||||||
<p>在Swift中,模式出现在变量和常量的声明(在它们的左侧),<code>for-in</code>语句和<code>switch</code>语句(在他们的case标签)中。尽管任何模式都可以出现在<code>switch</code>语句的case标签中,但在其他情况下,只有通配符模式(wildcard pattern),标识符模式(identifier pattern)和包含这两种模式的模式才能出现。</p>
|
<p>在Swift中,模式出现在变量和常量的声明(在它们的左侧),<code>for-in</code>语句和<code>switch</code>语句(在他们的case标签)中。尽管任何模式都可以出现在<code>switch</code>语句的case标签中,但在其他情况下,只有通配符模式(wildcard pattern),标识符模式(identifier pattern)和包含这两种模式的模式才能出现。</p>
|
||||||
<p>你可以为通配符模式(wildcard pattern),标识符模式(identifier pattern)和元组模式(tuple pattern)指定类型注释,用来限制这种模式只匹配某种类型的值。</p>
|
<p>你可以为通配符模式(wildcard pattern),标识符模式(identifier pattern)和元组模式(tuple pattern)指定类型注释,用来限制这种模式只匹配某种类型的值。</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="3.9" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="3.9" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -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_81">
|
||||||
|
|
||||||
<h1 id="-">泛型参数</h1>
|
<h1 id="-">泛型参数</h1>
|
||||||
<hr>
|
<hr>
|
||||||
|
|||||||
@ -44,7 +44,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="3.10" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="3.10" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -585,9 +585,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_63">
|
<section class="normal" id="section-gitbook_86">
|
||||||
|
|
||||||
<h1 id="-">语法总结</h1>
|
<h1 id="-">语法总结</h1>
|
||||||
|
<hr>
|
||||||
<p>本页包含内容:</p>
|
<p>本页包含内容:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#label1">语句(Statements)</a></li>
|
<li><a href="#label1">语句(Statements)</a></li>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="3.5" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="3.5" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
@ -587,9 +587,10 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_62">
|
<section class="normal" id="section-gitbook_83">
|
||||||
|
|
||||||
<h1 id="-">语句</h1>
|
<h1 id="-">语句</h1>
|
||||||
|
<hr>
|
||||||
<p>在 Swift 中,有两种类型的语句:简单语句和控制流语句。简单语句是最常见的,用于构造表达式和声明。控制流语句则用于控制程序执行的流程,Swift 中有三种类型的控制流语句:循环语句、分支语句和控制传递语句。</p>
|
<p>在 Swift 中,有两种类型的语句:简单语句和控制流语句。简单语句是最常见的,用于构造表达式和声明。控制流语句则用于控制程序执行的流程,Swift 中有三种类型的控制流语句:循环语句、分支语句和控制传递语句。</p>
|
||||||
<p>循环语句用于重复执行代码块;分支语句用于执行满足特定条件的代码块;控制传递语句则用于修改代码的执行顺序。在稍后的叙述中,将会详细地介绍每一种类型的控制流语句。</p>
|
<p>循环语句用于重复执行代码块;分支语句用于执行满足特定条件的代码块;控制传递语句则用于修改代码的执行顺序。在稍后的叙述中,将会详细地介绍每一种类型的控制流语句。</p>
|
||||||
<p>是否将分号(;)添加到语句的结尾处是可选的。但若要在同一行内写多条独立语句,请务必使用分号。</p>
|
<p>是否将分号(;)添加到语句的结尾处是可选的。但若要在同一行内写多条独立语句,请务必使用分号。</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="3" data-basepath=".." data-revision="1402397411238">
|
<div class="book" data-level="3" data-basepath=".." data-revision="1402402017737">
|
||||||
<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>
|
||||||
|
|||||||
@ -44,7 +44,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="0" data-basepath="." data-revision="1402397411238">
|
<div class="book" data-level="0" data-basepath="." data-revision="1402402017737">
|
||||||
<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>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
CACHE MANIFEST
|
CACHE MANIFEST
|
||||||
# Revision 1402397411239
|
# Revision 1402402017738
|
||||||
|
|
||||||
CACHE:
|
CACHE:
|
||||||
index.html
|
index.html
|
||||||
@ -23,11 +23,11 @@ chapter2/14_Initialization.html
|
|||||||
chapter2/15_Deinitialization.html
|
chapter2/15_Deinitialization.html
|
||||||
chapter2/16_Automatic_Reference_Counting.html
|
chapter2/16_Automatic_Reference_Counting.html
|
||||||
chapter2/17_Optional_Chaining.html
|
chapter2/17_Optional_Chaining.html
|
||||||
chapter2/19_Nested_Types.html
|
|
||||||
chapter2/18_Type_Casting.html
|
chapter2/18_Type_Casting.html
|
||||||
|
chapter2/19_Nested_Types.html
|
||||||
chapter2/20_Extensions.html
|
chapter2/20_Extensions.html
|
||||||
chapter2/21_Protocols.html
|
|
||||||
chapter2/22_Generics.html
|
chapter2/22_Generics.html
|
||||||
|
chapter2/21_Protocols.html
|
||||||
chapter2/23_Advanced_Operators.html
|
chapter2/23_Advanced_Operators.html
|
||||||
chapter2/chapter2.html
|
chapter2/chapter2.html
|
||||||
chapter3/06_Attributes.html
|
chapter3/06_Attributes.html
|
||||||
@ -39,8 +39,8 @@ chapter3/02_Lexical_Structure.html
|
|||||||
chapter3/07_Patterns.html
|
chapter3/07_Patterns.html
|
||||||
chapter3/08_Generic_Parameters_and_Arguments.html
|
chapter3/08_Generic_Parameters_and_Arguments.html
|
||||||
chapter3/10_Statements.html
|
chapter3/10_Statements.html
|
||||||
chapter3/09_Summary_of_the_Grammar.html
|
|
||||||
chapter3/chapter3.html
|
chapter3/chapter3.html
|
||||||
|
chapter3/09_Summary_of_the_Grammar.html
|
||||||
gitbook/app.js
|
gitbook/app.js
|
||||||
gitbook/fonts/anonymouspro/400.woff
|
gitbook/fonts/anonymouspro/400.woff
|
||||||
gitbook/fonts/anonymouspro/400i.woff
|
gitbook/fonts/anonymouspro/400i.woff
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user