iOS开发——swift篇&经典语法二十六)语法修正

 

多项改进

苹果全新编程语言 Swift 迎来了大幅更新,开发者可以使用 Swift 编写更好、更安全的应用。新版 Swift 编程语言修正了很多开发者提出的请求。此外,苹果也更新了介绍 Swift 的iBooks 书籍,反映出新变化。

更新时间:2014-07-07

更新内容:

  • Swift’s Array type now has full value semantics. Updated the information about Mutability of Collections and Arrays to reflect the new approach. Also clarified the Assignment and Copy Behavior for Strings, Arrays, and Dictionaries.
    • Array类型成为了数值类型,由结构来实现,所以在赋值或者作为参数传递的时候会拷贝一个全新的数值,而不像类一样,仅仅只是传递了一个引用。
    • 相应的第九章类与结构中Array和Dictionary的赋值和复制也有更新,翻译稿尽快推出。

 

  • Array Type Shorthand Syntax is now written as [SomeType] rather than SomeType[].
    • Array的书写形式由SomeType[]变为了[SomeType]
    • var shoppingList: [String] = ["Eggs", "Milk"]

 

  • Added a new section about Dictionary Type Shorthand Syntax, which is written as [KeyType: ValueType].
    • 字典类型的简写形式:[String: String]
    • var airports: [String: String] = ["TYO": "Tokyo", "DUB": "Dublin"]

 

  • Added a new section about Hash Values for Dictionary Key Types.
    • 作为字典类型中键的类型,必须是可哈希的
    • String,Int,Double和Bool类型都是可哈希的,所以可以作为字典的键

 

  • Examples of Closure Expressions now use the global sorted function rather than the global sort function, to reflect the new array value semantics.
    • 闭包表达式使用全局的sorted函数来表现新的数组语义

 

  • Updated the information about Memberwise Initializers for Structure Types to clarify that the memberwise structure initializer is made available even if a structure’s stored properties do not have default values.
    • 结构类型的成员逐一构造方法默认存在
    • 无论结构的属性是否有初始值都可以直接使用

 

  • Updated to ..< rather than .. for the Half-Closed Range Operator.
    • 左闭右开区间表示中,使用..<替代原有的..
    • 1 ..< 5表示1,2,3,4。1 … 5表示1,2,3,4,5
    • 这种书写方法更便于理解和使用

 

 
 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。