Swift 3.0 更改項目

更改項目說明

官方文章

Swift API Doc

SE-0002: Removing currying func declaration syntax

1
2
3
4
5
6
7
8
9
10
11
// Before:
func curried(x: Int)(y: String) -> Float {
return Float(x) + Float(y)!
}

// After:
func curried(x: Int) -> (String) -> Float {
return {(y: String) -> Float in
return Float(x) + Float(y)!
}
}

SE-0003: Removing var from Function Parameters

為了避免使用者混淆 inout 宣告,所以移除 Parameters var

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
func doSomethingWithVar(var i: Int) {
i = 2 // This will NOT have an effect on the caller's Int that was passed, but i can be modified locally
}

func doSomethingWithInout(inout i: Int) {
i = 2 // This will have an effect on the caller's Int that was passed.
}

var x = 1
print(x) // 1

doSomethingWithVar(x)
print(x) // 1

doSomethingWithInout(&x)
print(x) // 2

SE-0004: Remove the ++ and – operators

1
2
3
4
5
6
7
8
9
10
移除
let a = ++x // pre-increment - returns input value after mutation
let b = x++ // post-increment - returns copy of input value before mutation
let c = --x // pre-decrement - returns input value after mutation
let d = x-- // post-decrement - returns copy of input value before mutation


改用
x += 1
x -= 1

SE-0005: Better Translation of Objective-C APIs Into Swift

改進整合 OBJ-C API 到 Swift 中

SE-0006: Apply API Guidelines to the Standard Library

改一些 API 名稱

SE-0007: Remove C-style for-loops with conditions and incrementers

移除 C 語言的 for-loop,改用 Swift 的 for-in 和 stride

SE-0008: Add a Lazy flatMap for Sequences of Optionals

flatMap 有兩種版本寫法,原本只有其中一種有 lazy,現在另外一種也支援 lazy-flatmap-for-optionals

SE-0016: Adding initializers to Int and UInt to convert from UnsafePointer and UnsafeMutablePointer

加強 Swift pointer 的運算

SE-0017: Change Unmanaged to use UnsafePointer

SE-0019: Swift Testing

測試 module 改進

SE-0023: API Design Guidelines

改進說明

SE-0028: Modernizing Swift’s Debugging Identifiers (FILE, etc)

1
2
3
4
5
6
將原本 Snake case 命名改掉
__FILE__ -> #file
__LINE__ -> #line
__COLUMN__ -> #column
__FUNCTION__ -> #function (Added during review)
__DSO_HANDLE__ -> #dsohandle

SE-0029: Remove implicit tuple splat behavior from function applications

SE-0031: Adjusting inout Declarations for Type Decoration

調整 inout 宣告

SE-0032: Add first(where:) method to SequenceType

在 Sequence 類別中加入 first(where:) 方法

SE-0033: Import Objective-C Constants as Swift Types

將 OBJ-C 常數匯入成 Swift 的類型

SE-0034: Disambiguating Line Control Statements from Debugging Identifiers

SE-0037: Clarify interaction between comments & operators

註解在運算子旁邊的問題,改進某些 Case 會編譯錯誤

SE-0039: Modernizing Playground Literals

改進 Playground 中文宣告的問題

SE-0040: Replacing Equal Signs with Colons For Attribute Arguments

當比較 Attribute Arguments 時,使用冒號代替等號

SE-0043: Declare variables in ‘case’ labels with multiple patterns

改進在 switch 中宣告變數問題

SE-0044: Import as Member

SE-0046: Establish consistent label behavior across all parameters including first labels

SE-0047: Defaulting non-Void functions so they warn on unused results

SE-0048: Generic Type Aliases

typealias 泛型類別

SE-0049: Move @noescape and @autoclosure to be type attributes

SE-0053: Remove explicit use of let from Function Parameters

SE-0054: Abolish ImplicitlyUnwrappedOptional type

SE-0055: Make unsafe pointer nullability explicit using Optional

SE-0057: Importing Objective-C Lightweight Generics

SE-0059: Update API Naming Guidelines and Rewrite Set APIs Accordingly

SE-0061: Add Generic Result and Error Handling to autoreleasepool()

SE-0062: Referencing Objective-C key-paths

SE-0064: Referencing the Objective-C selector of property getters and setters

SE-0065: A New Model For Collections and Indices

SE-0066: Standardize function type argument syntax to require parentheses

SE-0069: Mutability and Foundation Value Types

SE-0070: Make Optional Requirements Objective-C-only

SE-0071: Allow (most) keywords in member references

SE-0085: Package Manager Command Names

SE-0094: Add sequence(first:next:) and sequence(state:next:) to the stdlib