From 6c313fbc5d09802698a124c450a17ba0439c88c1 Mon Sep 17 00:00:00 2001 From: XiaoleTao Date: Sun, 15 Jun 2014 18:14:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E5=A4=84

=E7=9A=84id=E6=9C=89?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E5=B7=B2=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chapter1/02_a_swift_tour.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/chapter1/02_a_swift_tour.html b/chapter1/02_a_swift_tour.html index 4e94da14..a9265ced 100644 --- a/chapter1/02_a_swift_tour.html +++ b/chapter1/02_a_swift_tour.html @@ -617,7 +617,7 @@ plauground版本原链接: https://developer.apple.com/library/prerelease/ios/ -->

-

简单值

+

简单值

使用let来声明常量,使用var来声明变量。一个常量的值,在编译的时候,并不需要有明确的值,但是你只能为它赋值一次。也就是说你可以用常量来表示这样一个值:你只需要决定一次,但是需要使用很多次。

var myVariable = 42
 myVariable = 50
@@ -667,7 +667,7 @@ let emptyDictionary = Dictionary<String, Float>()
 
shoppingList = []   // 去逛街并买点东西
 

-

控制流

+

控制流

使用ifswitch来进行条件操作,使用for-inforwhiledo-while来进行循环。包裹条件和循环变量括号可以省略,但是语句体的大括号是必须的。

let individualScores = [75, 43, 103, 87, 12]
 var teamScore = 0
@@ -759,7 +759,7 @@ secondForLoop
 

使用..创建的范围不包含上界,如果想包含的话需要使用...

-

函数和闭包

+

函数和闭包

使用func来声明一个函数,使用名字和参数来调用函数。使用->来指定函数返回值。

func greet(name: String, day: String) -> String {
     return "Hello \(name), today is \(day)."
@@ -975,7 +975,7 @@ counter.incrementBy(2, numberOfTimes: 7)
 let sideLength = optionalSquare?.sideLength
 

-

枚举和结构体

+

枚举和结构体

使用enum来创建一个枚举。就像类和其他所有命名类型一样,枚举可以包含方法。

enum Rank: Int {
     case Ace = 1
@@ -1070,7 +1070,7 @@ case let .Error(error):
 
 

注意如何从ServerResponse中提取日升和日落时间。

-

协议和扩展

+

协议和扩展

使用protocol来声明一个协议。

protocol ExampleProtocol {
     var simpleDescription: String { get }
@@ -1126,7 +1126,7 @@ protocolValue.simpleDescription
 

即使protocolValue变量运行时的类型是simpleClass,编译器会把它的类型当做ExampleProtocol。这表示你不能调用类在它实现的协议之外实现的方法或者属性。

-

泛型

+

泛型

在尖括号里写一个名字来创建一个泛型函数或者类型。

func repeat<ItemType>(item: ItemType, times: Int) -> ItemType[] {
     var result = ItemType[]()