diff --git a/chapter1/01_swift.html b/chapter1/01_swift.html index 4649973a..d7025e3d 100644 --- a/chapter1/01_swift.html +++ b/chapter1/01_swift.html @@ -46,7 +46,7 @@ -
Swift 是一种新的编程语言,用于编写 iOS 和 OS X 应用程序。Swift 结合了 C 和 Objective-C 的优点并且不受C的兼容性的限制。Swift 使用安全的编程模式并添加了很多新特性,这将使编程更简单,扩展性更强,也更有趣。除此之外,Swift 还支持人见人爱的 Cocoa 和 Cocoa Touch 框架。拥有了这些特性,Swift将重新定义软件开发。
diff --git a/chapter1/02_a_swift_tour.html b/chapter1/02_a_swift_tour.html index 50ed970b..c0a7eda8 100644 --- a/chapter1/02_a_swift_tour.html +++ b/chapter1/02_a_swift_tour.html @@ -46,7 +46,7 @@ -通常来说,编程语言教程中的第一个程序应该在屏幕上打印“Hello, world”。在 Swift 中,可以用一行代码实现:
diff --git a/chapter1/chapter1.html b/chapter1/chapter1.html index 1399784a..95c45972 100644 --- a/chapter1/chapter1.html +++ b/chapter1/chapter1.html @@ -46,7 +46,7 @@ -在本章中您将了解 Swift 的特性和开发历史,并对 Swift 有一个初步的了解。
diff --git a/chapter2/01_The_Basics.html b/chapter2/01_The_Basics.html index 2036edc6..f94d4ec0 100644 --- a/chapter2/01_The_Basics.html +++ b/chapter2/01_The_Basics.html @@ -46,7 +46,7 @@ -Swift 是 iOS 和 OS X 应用开发的一门新语言。然而,如果你有 C 或者 Objective-C 开发经验的话,你会发现 Swift 的很多内容都是你熟悉的。
@@ -661,7 +661,41 @@ this is the end of the first multiline comment */与其他大部分编程语言不同,Swift 并不强制要求你在每条语句的结尾处使用分号(;),当然,你也可以按照你自己的习惯添加分号。有一种情况下必须要用分号,即你打算在同一行内写多条独立的语句:
let cat = "🐱"; println(cat)
// prints "🐱"
-
+整数就是没有小数部分的数字,比如42和23。整数分有符号(正、负、零)或者无符号(正、零)两种。
Swift 提供了8、16、32和64位的有符号和无符号整数。这些整数和 C 的命名习惯很像,比如8位无符号整数类型是UInt8,32位有符号整数类型是Int32。就像 Swift 的其他类型一样,这些整数类型的名字使用大写字母来命名。
你可以访问每个整数类型的min和max属性来获取这个类型的最小值和最大值:
let minValue = UInt8.min // UInt8 类型的 minValue 等于0
+let maxValue = UInt8.max // UInt8 类型的 maxValue 等于255
+这两个值的类型和右侧的整数类型是相同的(比如例子中的UInt8),因此你可以在表达式中把它们和同类型的值一同使用。
大多数情况下,你并不需要指定整数长度。Swift 提供了一个特别的整数类型Int,这个类型的长度和当前平台的原生字长一样:
Int和Int32长度相同Int和Int64长度相同一般来说,最好使用Int类型,除非你需要指定整数长度。这可以保证代码的一致性和可复用性。即使在32位平台上,Int也可以存储范围为-2147483648~2147483647的整数,大多数时候这已经够用了。
Swift 还提供了一个无符号整数类型UInt,这个类型的长度和当前平台的原生字长一样:
UInt和UInt32长度相同UInt和UInt64长度相同++注意:只在你需要使用无符号整数类型并且长度和平台原生字长相同的时候才使用
+Uint。如果不是这种情况,最好使用Int,即使要存储的值已知是非负数。使用Int可以保证代码的可复用性,避免不同类型之间的转换,并且符合整数类型推测,详情请见类型安全和类型推测(待添加链接)。
浮点数是有小数部分的数字,比如3.14159,0.1和-273.15。
浮点类型可以表示的数字范围比整数类型要大,因此可以存储比Int类型更大或者更小的数字。Swift 提供了两种有符号浮点数类型:
Double表示64位浮点数。当浮点值非常大或者需要非常准确的时候使用此类型。Float表示32位浮点数。当浮点值不需要使用Double的时候使用此类型。++注意:
+Double的准确程度是至少15个十进制数字,而Float的准确程度是至少6个十进制数字。到底选择哪个浮点类型取决于你要存储的值。
String 是一个有序的字符集合,例如 "hello, world", "albatross"。Swift 字符串通过 String 类型来表示,也可以表示为 Character 类型值的集合。
diff --git a/chapter2/04_Collection_Types.html b/chapter2/04_Collection_Types.html index 650a57f4..ed625c17 100644 --- a/chapter2/04_Collection_Types.html +++ b/chapter2/04_Collection_Types.html @@ -46,7 +46,7 @@ -函数是用来完成特定任务的独立的代码块。你给一个函数起一个合适的名字,用来标示函数做什么,并且当函数需要执行的时候,这个名字会被“调用”。
diff --git a/chapter2/07_Closures.html b/chapter2/07_Closures.html index 2cde4b3e..c835d161 100644 --- a/chapter2/07_Closures.html +++ b/chapter2/07_Closures.html @@ -46,7 +46,7 @@ -本章介绍了 Swift 的各种特性及其使用方法,是全书的核心部分。
diff --git a/chapter3/01_About_the_Language_Reference.html b/chapter3/01_About_the_Language_Reference.html index 0f74ddfb..b89a228a 100644 --- a/chapter3/01_About_the_Language_Reference.html +++ b/chapter3/01_About_the_Language_Reference.html @@ -46,7 +46,7 @@ -Swift 是苹果在 WWDC 2014 上发布的一款全新的编程语言,本书译自苹果官方的 Swift 教程《The Swift Programming Language》。
diff --git a/manifest.appcache b/manifest.appcache index 5e27c327..c162b78b 100644 --- a/manifest.appcache +++ b/manifest.appcache @@ -1,5 +1,5 @@ CACHE MANIFEST -# Revision 1401951667607 +# Revision 1401953615321 CACHE: index.html diff --git a/search_index.json b/search_index.json index 3dfb31cc..1e1e71ab 100644 --- a/search_index.json +++ b/search_index.json @@ -1 +1 @@ -{"version":"0.5.2","fields":[{"name":"title","boost":10},{"name":"body","boost":1}],"ref":"url","documentStore":{"store":{"index.html#gitbook_4":["2014","languag","program","swift","undefinedundefin","wwdc"],"chapter1/01_swift.html#gitbook_5":["arc","automat","c","cocoa","cocoa的基础上构建框架栈并将其标准化。objective-c","count","c的兼容性的限制。swift","foundat","hello","io","objective-c","os","refer","swift","touch","undefinedundefin","world","x"],"chapter1/02_a_swift_tour.html#gitbook_6":["0","0..3","0..time","0.0","1","10","100","103","11","12","13","16","19","2","2.5","20","25","3","3.0","3.1","3.59","3.69","3.79","4","42","43","5","5.2","50","597","69105","7","7.simpledescript","70","70.0","75","8","87","8:09","9","9.9","94","a.adjust","a.simpledescript","ac","ace.toraw","acerawvalu","add","addon","addone(numb","adescript","adjust","amount","anoth","anotherproperti","ant","anycommonel","anycommonelements([1","appl","applese","applesummari","area","b","b.adjust","b.simpledescript","bdescript","blue","bool","bottl","c","captain","card","card(rank","card添加一个方法,创建一副完整的扑克牌并把每张牌的rank和suit","case","catfish","celeri","chees","class","club","condit","condition(item","convertedrank","convertedrank.simpledescript","count","counter","counter.incrementby(2","cucumb","dai","default","deinit","diamond","dictionary