update 02/08
This commit is contained in:
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="1.1" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="1.1" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_62">
|
<section class="normal" id="section-gitbook_5">
|
||||||
|
|
||||||
<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>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="1.2" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="1.2" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_63">
|
<section class="normal" id="section-gitbook_6">
|
||||||
|
|
||||||
<h1 id="swift-">Swift 初见</h1>
|
<h1 id="swift-">Swift 初见</h1>
|
||||||
<p>本页内容包括:</p>
|
<p>本页内容包括:</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="1" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="1" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_64">
|
<section class="normal" id="section-gitbook_7">
|
||||||
|
|
||||||
<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="1402235469937">
|
<div class="book" data-level="2.1" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_66">
|
<section class="normal" id="section-gitbook_9">
|
||||||
|
|
||||||
<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>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.2" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.2" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_88">
|
<section class="normal" id="section-gitbook_31">
|
||||||
|
|
||||||
<h1 id="-">基础运算符</h1>
|
<h1 id="-">基础运算符</h1>
|
||||||
<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>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.3" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.3" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_67">
|
<section class="normal" id="section-gitbook_10">
|
||||||
|
|
||||||
<h1 id="-strings-and-characters-">字符串和字符 (Strings and Characters)</h1>
|
<h1 id="-strings-and-characters-">字符串和字符 (Strings and Characters)</h1>
|
||||||
<p>本页包含内容:</p>
|
<p>本页包含内容:</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.4" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.4" data-basepath=".." data-revision="1402238318316">
|
||||||
<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.5" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.5" data-basepath=".." data-revision="1402238318316">
|
||||||
<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.6" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.6" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_81">
|
<section class="normal" id="section-gitbook_24">
|
||||||
|
|
||||||
<h1 id="-functions-">函数(Functions)</h1>
|
<h1 id="-functions-">函数(Functions)</h1>
|
||||||
<p>本页包含内容:</p>
|
<p>本页包含内容:</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.7" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.7" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_82">
|
<section class="normal" id="section-gitbook_25">
|
||||||
|
|
||||||
<h1 id="-">闭包</h1>
|
<h1 id="-">闭包</h1>
|
||||||
<p>本页内容包含:</p>
|
<p>本页内容包含:</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.8" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.8" data-basepath=".." data-revision="1402238318316">
|
||||||
<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,6 +587,153 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
|
<section class="normal" id="section-gitbook_26">
|
||||||
|
|
||||||
|
<h1 id="-">枚举</h1>
|
||||||
|
<p>本页内容包含:</p>
|
||||||
|
<ul>
|
||||||
|
<li>枚举语法</li>
|
||||||
|
<li>匹配枚举值与<code>Swith</code>语句</li>
|
||||||
|
<li>实例值(associated values)</li>
|
||||||
|
<li>原始值(raw values)</li>
|
||||||
|
</ul>
|
||||||
|
<p>枚举(enumeration)定义了一个通用类型的一组相关的值,使你可以在你的代码中以一个安全的方式来使用这些值。</p>
|
||||||
|
<p>如果你熟悉C语言,你就会知道,在C语言中枚举指定相关名称为一组整型值。Swift中的枚举更加灵活,不必给每一个枚举成员(enumeration member)提供一个值。如果一个值(被认为是“原始”值)被提供给每个枚举成员,则该值可以是一个字符串,一个字符,或是一个整型值或浮点值。</p>
|
||||||
|
<p>此外,枚举成员可以指定任何类型的实例值存储到枚举成员值中,就像其他语言中的联合体(unions)和变体(variants)。你可以定义一组通用的相关成员作为枚举的一部分,每一组都有不同的一组与它相关的适当类型的数值。</p>
|
||||||
|
<p>在Swift中,枚举类型是一等(first-class)类型。它们采用了很多传统上只被类(class)所支持的特征,例如计算型属性(computed properties),用于提供关于枚举当前值的附加信息, 实例方法(instance methods),用于提供和枚举所代表的值相关联的功能。枚举也可以定义构造函数(initializers)来提供一个初始成员值;可以在原始的实现基础上扩展它们的功能;可以遵守协议(protocols)来提供标准的功能。</p>
|
||||||
|
<p>欲了解更多相关功能,请参见属性(Properties),方法(Methods),构造过程(Initialization),扩展(Extensions),和协议(Protocols)。</p>
|
||||||
|
<h2 id="-">枚举语法</h2>
|
||||||
|
<p>使用<code>enum</code>关键词并且把它们的整个定义放在一对大括号内:</p>
|
||||||
|
<pre><code>enum SomeEumeration {
|
||||||
|
// enumeration definition goes here
|
||||||
|
}
|
||||||
|
</code></pre><p>以下是指南针四个方向的一个例子:</p>
|
||||||
|
<pre><code>enum CompassPoint {
|
||||||
|
case North
|
||||||
|
case South
|
||||||
|
case East
|
||||||
|
case West
|
||||||
|
}
|
||||||
|
</code></pre><p>一个枚举中被定义的值(例如 <code>North</code>,<code>South</code>,<code>East</code>和<code>West</code>)是枚举的<strong><em>成员值</em></strong>(或者<strong><em>成员</em></strong>)。<code>case</code>关键词表明新的一行成员值将被定义。</p>
|
||||||
|
<blockquote>
|
||||||
|
<p>注意:
|
||||||
|
不像C和Objective-C一样,Swift的枚举成员在被创建时不会被赋予一个默认的整数值。在上面的<code>CompassPoints</code>例子中,<code>North</code>,<code>South</code>,<code>East</code>和<code>West</code>不是隐式得等于<code>0</code>,<code>1</code>,<code>2</code>和<code>3</code>。相反的,这些不同的枚举成员在<code>CompassPoint</code>的一种显示定义中拥有各自不同的值。</p>
|
||||||
|
</blockquote>
|
||||||
|
<p>多个成员值可以出现在同一行上,用逗号隔开:</p>
|
||||||
|
<pre><code>enum Planet {
|
||||||
|
case Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Nepturn
|
||||||
|
}
|
||||||
|
</code></pre><p>每个枚举定义了一个全新的类型。像Swift中其他类型一样,它们的名字(例如<code>CompassPoint</code>和<code>Planet</code>)必须以一个大写字母开头。给枚举类型起一个单数名字而不是复数名字,以便于读起来更加容易理解:</p>
|
||||||
|
<pre><code>var directionToHead = CompassPoint.West
|
||||||
|
</code></pre><p><code>directionToHead</code>的类型被推断当它被<code>CompassPoint</code>的一个可能值初始化。一旦<code>directionToHead</code>被声明为一个<code>CompassPoint</code>,你可以使用更短的点(.)语法将其设置为另一个<code>CompassPoint</code>的值:</p>
|
||||||
|
<pre><code>directionToHead = .East
|
||||||
|
</code></pre><p><code>directionToHead</code>的类型已知时,当设定它的值时,你可以不再写类型名。使用显示类型的枚举值可以让代码具有更好的可读性。</p>
|
||||||
|
<h2 id="-switch-">匹配枚举值和<code>Switch</code>语句</h2>
|
||||||
|
<p>你可以匹配单个枚举值和<code>switch</code>语句:</p>
|
||||||
|
<pre><code>directionToHead = .South
|
||||||
|
switch directionToHead {
|
||||||
|
case .North:
|
||||||
|
println("Lots of planets have a north")
|
||||||
|
case .South:
|
||||||
|
println("Watch out for penguins")
|
||||||
|
case .East:
|
||||||
|
println("Where the sun rises")
|
||||||
|
case .West:
|
||||||
|
println("Where the skies are blue")
|
||||||
|
}
|
||||||
|
// prints "Watch out for penguins”
|
||||||
|
</code></pre><p>你可以如此理解这段代码:</p>
|
||||||
|
<p>“考虑<code>directionToHead</code>的值。当它等于<code>.North</code>,打印<code>“Lots of planets have a north”</code>。当它等于<code>.South</code>,打印<code>“Watch out for penguins”</code>。”</p>
|
||||||
|
<p>等等依次类推。</p>
|
||||||
|
<p>正如在控制流(Control Flow)中介绍,当考虑一个枚举的成员们时,一个<code>switch</code>语句必须全面。如果忽略了<code>.West</code>这种情况,上面那段代码将无法通过编译,因为它没有考虑到<code>CompassPoint</code>的全部成员。全面性的要求确保了枚举成员不会被意外遗漏。</p>
|
||||||
|
<p>当不需要匹配每个枚举成员的时候,你可以提供一个默认<code>default</code>分支来涵盖所有未明确被提出的任何成员:</p>
|
||||||
|
<pre><code>let somePlanet = Planet.Earth
|
||||||
|
switch somePlanet {
|
||||||
|
case .Earth:
|
||||||
|
println("Mostly harmless")
|
||||||
|
default:
|
||||||
|
println("Not a safe place for humans")
|
||||||
|
}
|
||||||
|
// prints "Mostly harmless”
|
||||||
|
</code></pre><h2 id="-associated-values-">实例值(Associated Values)</h2>
|
||||||
|
<p>上一小节的例子演示了一个枚举的成员是如何被定义(分类)的。你可以为<code>Planet.Earth</code>设置一个常量或则变量,并且在之后查看这个值。然而,有时候会很有用如果能够把其他类型的实例值和成员值一起存储起来。这能让你随着成员值存储额外的自定义信息,并且当每次你在代码中利用该成员时允许这个信息产生变化。</p>
|
||||||
|
<p>你可以定义Swift的枚举存储任何类型的实例值,如果需要的话,每个成员的数据类型可以是各不相同的。枚举的这种特性跟其他语言中的可辨识联合(discriminated unions),标签联合(tagged unions),或者变体(variants)相似。</p>
|
||||||
|
<p>例如,假设一个库存跟踪系统需要利用两种不同类型的条形码来跟踪商品。有些商品上标有UPC-A格式的一维码,它使用数字0到9.每一个条形码都有一个代表“数字系统”的数字,该数字后接10个代表“标识符”的数字。最后一个数字是“检查”位,用来验证代码是否被正确扫描:</p>
|
||||||
|
<p><img width="252" height="120" a"" src="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Art/barcode_UPC_2x.png"></p>
|
||||||
|
<p>其他商品上标有QR码格式的二维码,它可以使用任何ISO8859-1字符,并且可以编码一个最多拥有2,953字符的字符串:</p>
|
||||||
|
<p><img width="169" height="169" alt="" src="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Art/barcode_QR_2x.png"></p>
|
||||||
|
<p>对于库存跟踪系统来说,能够把UPC-A码作为三个整型值的元组,和把QR码作为一个任何长度的字符串存储起来是方便的。</p>
|
||||||
|
<p>在Swift中,用来定义两种商品条码的枚举是这样子的:</p>
|
||||||
|
<pre><code>enum Barcode {
|
||||||
|
case UPCA(Int, Int, Int)
|
||||||
|
case QRCode(String)
|
||||||
|
}
|
||||||
|
</code></pre><p>以上代码可以这么理解:</p>
|
||||||
|
<p>“定义一个名为<code>Barcode</code>的枚举类型,它可以是<code>UPCA</code>的一个实例值(<code>Int</code>,<code>Int</code>,<code>Int</code>),或者<code>QRCode</code>的一个字符串类型(<code>String</code>)实例值。”</p>
|
||||||
|
<p>这个定义不提供任何<code>Int</code>或<code>String</code>的实际值,它只是定义了,当<code>Barcode</code>常量和变量等于<code>Barcode.UPCA</code>或<code>Barcode.QRCode</code>时,实例值的类型。</p>
|
||||||
|
<p>然后可以使用任何一种条码类型创建新的条码,如:</p>
|
||||||
|
<pre><code>var productBarcode = Barcode.UPCA(8, 85909_51226, 3)
|
||||||
|
</code></pre><p>以上例子创建了一个名为<code>productBarcode</code>的新变量,并且赋给它一个<code>Barcode.UPCA</code>的实例元组值<code>(8, 8590951226, 3)</code>。提供的“标识符”值在整数字中有一个下划线,使其便于阅读条形码。</p>
|
||||||
|
<p>同一个商品可以被分配给一个不同类型的条形码,如:</p>
|
||||||
|
<pre><code>productBarcode = .QRCode("ABCDEFGHIJKLMNOP")
|
||||||
|
</code></pre><p>这时,原始的<code>Barcode.UPCA</code>和其整数值被新的<code>Barcode.QRCode</code>和其字符串值所替代。条形码的常量和变量可以存储一个<code>.UPCA</code>或者一个<code>.QRCode</code>(连同它的实例值),但是在任何指定时间只能存储其中之一。</p>
|
||||||
|
<p>像以前那样,不同的条形码类型可以使用一个switch语句来检查,然而这次实例值可以被提取作为switch语句的一部分。你可以在<code>switch</code>的case分支代码中提取每个实例值作为一个常量(用<code>let</code>前缀)或者作为一个变量(用<code>var</code>前缀)来使用:</p>
|
||||||
|
<pre><code>switch productBarcode {
|
||||||
|
case .UPCA(let numberSystem, let identifier, let check):
|
||||||
|
println("UPC-A with value of \(numberSystem), \(identifier), \(check).")
|
||||||
|
case .QRCode(let productCode):
|
||||||
|
println("QR code with value of \(productCode).")
|
||||||
|
}
|
||||||
|
// prints "QR code with value of ABCDEFGHIJKLMNOP.”
|
||||||
|
</code></pre><p>如果一个枚举成员的所有实例值被提取为常量,或者它们全部被提取为变量,为了简洁,你可以只放置一个<code>var</code>或者<code>let</code>标注在成员名称前:</p>
|
||||||
|
<pre><code>switch productBarcode {
|
||||||
|
case let .UPCA(numberSystem, identifier, check):
|
||||||
|
println("UPC-A with value of \(numberSystem), \(identifier), \(check).")
|
||||||
|
case let .QRCode(productCode):
|
||||||
|
println("QR code with value of \(productCode).")
|
||||||
|
}
|
||||||
|
// prints "QR code with value of ABCDEFGHIJKLMNOP."
|
||||||
|
</code></pre><h2 id="-raw-values-">原始值(Raw Values)</h2>
|
||||||
|
<p>在实例值小节的条形码例子中演示了一个枚举的成员如何声明它们存储不同类型的实例值。作为实例值的替代,枚举成员可以被默认值(称为原始值)预先填充,其中这些原始值具有相同的类型。</p>
|
||||||
|
<p>这里是一个枚举成员存储原始ASCII值的例子:</p>
|
||||||
|
<pre><code>enum ASCIIControlCharacter: Character {
|
||||||
|
case Tab = "\t"
|
||||||
|
case LineFeed = "\n"
|
||||||
|
case CarriageReturn = "\r"
|
||||||
|
}
|
||||||
|
</code></pre><p>在这里,称为<code>ASCIIControlCharacter</code>的枚举的原始值类型被定义为字符型<code>Character</code>,并被设置了一些比较常见的ASCII控制字符。字符值的描述请详见字符串和字符<code>Strings and Characters</code>部分。</p>
|
||||||
|
<p>注意,原始值和实例值是不相同的。当你开始在你的代码中定义枚举的时候原始值是被预先填充的值,像上述三个ASCII码。对于一个特定的枚举成员,它的原始值始终是相同的。实例值是当你在创建一个基于枚举成员的新常量或变量时才会被设置,并且每次当你这么做得时候,它的值可以是不同的。</p>
|
||||||
|
<p>原始值可以是字符串,字符,或者任何整型值或浮点型值。每个原始值在它的枚举声明中必须是唯一的。当整型值被用于原始值,如果其他枚举成员没有值时,它们会自动递增。</p>
|
||||||
|
<p>下面的枚举是对之前<code>Planet</code>这个枚举的一个细化,利用原始整型值来表示每个planet在太阳系中的顺序:</p>
|
||||||
|
<pre><code>enum Planet: Int {
|
||||||
|
case Mercury = 1, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune
|
||||||
|
}
|
||||||
|
</code></pre><p>自动递增意味着<code>Planet.Venus</code>的原始值是<code>2</code>,依次类推。</p>
|
||||||
|
<p>使用枚举成员的<code>toRaw</code>方法可以访问该枚举成员的原始值:</p>
|
||||||
|
<pre><code>let earthsOrder = Planet.Earth.toRaw()
|
||||||
|
// earthsOrder is 3
|
||||||
|
</code></pre><p>使用枚举的<code>fromRaw</code>方法来试图找到具有特定原始值的枚举成员。这个例子通过原始值<code>7</code>识别<code>Uranus</code>:</p>
|
||||||
|
<pre><code>let possiblePlanet = Planet.fromRaw(7)
|
||||||
|
// possiblePlanet is of type Planet? and equals Planet.Uranus
|
||||||
|
</code></pre><p>然而,并非所有可能的<code>Int</code>值都可以找到一个匹配的行星。正因为如此,<code>fromRaw</code>方法可以返回一个<strong><em>可选</em></strong>的枚举成员。在上面的例子中,<code>possiblePlanet</code>是<code>Planet?</code>类型,或“可选的<code>Planet</code>”。</p>
|
||||||
|
<p>如果你试图寻找一个位置为9的行星,通过<code>fromRaw</code>返回的可选<code>Planet</code>值将是<code>nil</code>:</p>
|
||||||
|
<pre><code>let positionToFind = 9
|
||||||
|
if let somePlanet = Planet.fromRaw(positionToFind) {
|
||||||
|
switch somePlanet {
|
||||||
|
case .Earth:
|
||||||
|
println("Mostly harmless")
|
||||||
|
default:
|
||||||
|
println("Not a safe place for humans")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println("There isn't a planet at position \(positionToFind)")
|
||||||
|
}
|
||||||
|
// prints "There isn't a planet at position 9
|
||||||
|
</code></pre><p>这个范例使用可选绑定(optional binding),通过原始值<code>9</code>试图访问一个行星。<code>if let somePlanet = Planet.fromRaw(9)</code>语句获得一个可选<code>Planet</code>,如果可选<code>Planet</code>可以被获得,把<code>somePlanet</code>设置成该可选<code>Planet</code>的内容。在这个范例中,无法检索到位置为<code>9</code>的行星,所以<code>else</code>分支被执行。</p>
|
||||||
|
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.9" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.9" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_84">
|
<section class="normal" id="section-gitbook_27">
|
||||||
|
|
||||||
<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="1402235469937">
|
<div class="book" data-level="2.10" data-basepath=".." data-revision="1402238318316">
|
||||||
<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.11" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.11" data-basepath=".." data-revision="1402238318316">
|
||||||
<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.12" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.12" data-basepath=".." data-revision="1402238318316">
|
||||||
<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.13" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.13" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_65">
|
<section class="normal" id="section-gitbook_8">
|
||||||
|
|
||||||
<h1 id="-">继承</h1>
|
<h1 id="-">继承</h1>
|
||||||
<p>一个类可以继承另一个类的方法,属性和其它特性。当一个类继承其它类,继承类叫子类,被继承类叫超类(或父类)。在Swift中,继承是区分「类」与其它类型的一个基本特征。</p>
|
<p>一个类可以继承另一个类的方法,属性和其它特性。当一个类继承其它类,继承类叫子类,被继承类叫超类(或父类)。在Swift中,继承是区分「类」与其它类型的一个基本特征。</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.14" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.14" data-basepath=".." data-revision="1402238318316">
|
||||||
<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="1402235469937">
|
<div class="book" data-level="2.15" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_90">
|
<section class="normal" id="section-gitbook_33">
|
||||||
|
|
||||||
<h1 id="-">析构过程</h1>
|
<h1 id="-">析构过程</h1>
|
||||||
<p>在一个类的实例被释放之前,析构函数被立即调用。用关键字deinit来标示析构函数,类似于初始化函数用init来标示。析构函数只适用于类类型。</p>
|
<p>在一个类的实例被释放之前,析构函数被立即调用。用关键字deinit来标示析构函数,类似于初始化函数用init来标示。析构函数只适用于类类型。</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.16" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.16" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_91">
|
<section class="normal" id="section-gitbook_34">
|
||||||
|
|
||||||
<h1 id="-">自动引用计数</h1>
|
<h1 id="-">自动引用计数</h1>
|
||||||
<p>本页包含内容:</p>
|
<p>本页包含内容:</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.17" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.17" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_92">
|
<section class="normal" id="section-gitbook_35">
|
||||||
|
|
||||||
<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>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.18" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.18" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_93">
|
<section class="normal" id="section-gitbook_36">
|
||||||
|
|
||||||
<h1 id="-type-casting-">类型检查(Type Casting)</h1>
|
<h1 id="-type-casting-">类型检查(Type Casting)</h1>
|
||||||
<p>(ps:为了方便各位检验所以保留了英文,可删。)
|
<p>(ps:为了方便各位检验所以保留了英文,可删。)
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.19" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.19" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_94">
|
<section class="normal" id="section-gitbook_37">
|
||||||
|
|
||||||
<h1 id="-">类型嵌套</h1>
|
<h1 id="-">类型嵌套</h1>
|
||||||
<p>本页包含内容:</p>
|
<p>本页包含内容:</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.20" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.20" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_95">
|
<section class="normal" id="section-gitbook_38">
|
||||||
|
|
||||||
<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="1402235469937">
|
<div class="book" data-level="2.21" data-basepath=".." data-revision="1402238318316">
|
||||||
<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.22" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.22" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_98">
|
<section class="normal" id="section-gitbook_41">
|
||||||
|
|
||||||
<h1 id="-">泛型</h1>
|
<h1 id="-">泛型</h1>
|
||||||
<hr>
|
<hr>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="2.23" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2.23" data-basepath=".." data-revision="1402238318316">
|
||||||
<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" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="2" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_102">
|
<section class="normal" id="section-gitbook_45">
|
||||||
|
|
||||||
<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="1402235469937">
|
<div class="book" data-level="3.1" data-basepath=".." data-revision="1402238318316">
|
||||||
<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_104">
|
<section class="normal" id="section-gitbook_47">
|
||||||
|
|
||||||
<h1 id="-">关于语言附注</h1>
|
<h1 id="-">关于语言附注</h1>
|
||||||
<p>本书的这一节描述了Swift编程语言的形式语法。这里描述的语法是为了帮助您更详细的了解该语言,而不是让您直接实现一个解析器或编译器。</p>
|
<p>本书的这一节描述了Swift编程语言的形式语法。这里描述的语法是为了帮助您更详细的了解该语言,而不是让您直接实现一个解析器或编译器。</p>
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="book" data-level="3.2" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="3.2" data-basepath=".." data-revision="1402238318316">
|
||||||
<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.3" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="3.3" data-basepath=".." data-revision="1402238318316">
|
||||||
<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.4" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="3.4" data-basepath=".." data-revision="1402238318316">
|
||||||
<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.6" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="3.6" data-basepath=".." data-revision="1402238318316">
|
||||||
<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="1402235469937">
|
<div class="book" data-level="3.7" data-basepath=".." data-revision="1402238318316">
|
||||||
<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.8" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="3.8" data-basepath=".." data-revision="1402238318316">
|
||||||
<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.9" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="3.9" data-basepath=".." data-revision="1402238318316">
|
||||||
<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="3.10" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="3.10" data-basepath=".." data-revision="1402238318316">
|
||||||
<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.5" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="3.5" data-basepath=".." data-revision="1402238318316">
|
||||||
<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" data-basepath=".." data-revision="1402235469937">
|
<div class="book" data-level="3" data-basepath=".." data-revision="1402238318316">
|
||||||
<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="1402235469937">
|
<div class="book" data-level="0" data-basepath="." data-revision="1402238318316">
|
||||||
<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,7 +585,7 @@
|
|||||||
|
|
||||||
<div class="page-inner">
|
<div class="page-inner">
|
||||||
|
|
||||||
<section class="normal" id="section-gitbook_61">
|
<section class="normal" id="section-gitbook_4">
|
||||||
|
|
||||||
<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>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
CACHE MANIFEST
|
CACHE MANIFEST
|
||||||
# Revision 1402235469938
|
# Revision 1402238318317
|
||||||
|
|
||||||
CACHE:
|
CACHE:
|
||||||
index.html
|
index.html
|
||||||
@ -15,8 +15,8 @@ chapter2/06_Functions.html
|
|||||||
chapter2/07_Closures.html
|
chapter2/07_Closures.html
|
||||||
chapter2/08_Enumerations.html
|
chapter2/08_Enumerations.html
|
||||||
chapter2/09_Classes_and_Structures.html
|
chapter2/09_Classes_and_Structures.html
|
||||||
chapter2/10_Properties.html
|
|
||||||
chapter2/11_Methods.html
|
chapter2/11_Methods.html
|
||||||
|
chapter2/10_Properties.html
|
||||||
chapter2/12_Subscripts.html
|
chapter2/12_Subscripts.html
|
||||||
chapter2/02_Basic_Operators.html
|
chapter2/02_Basic_Operators.html
|
||||||
chapter2/14_Initialization.html
|
chapter2/14_Initialization.html
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user