Yume 練功地

偷偷練

swift 3.0 閱讀

Swift 3.0 閱讀準備
swift-evolution

2016-02-16

Proposals (Swift 2.2 已實現)

1 Allow (most) keywords as argument labels

主要訴求:在參數中可使用 `關鍵字(keywords)`
訴求
1
indexOf(value, in: collection)
實作方式
1
indexOf(value, `in`: collection)

11 Replace typealias keyword with associatedtype for associated type declarations
14 Constraining AnySequence.init
15 Tuple comparison operators

主要訴求:節省 tuple comparison implement code 的麻煩事。
1
2
3
4
5
6
7
8
9
10
11
@warn_unused_result
public func == <A: Equatable, B: Equatable, C: Equatable>(lhs: (A,B,C), rhs: (A,B,C)) -> Bool {
return lhs.0 == rhs.0 && lhs.1 == rhs.1 && lhs.2 == rhs.2
}

@warn_unused_result
public func < <A: Comparable, B: Comparable, C: Comparable>(lhs: (A,B,C), rhs: (A,B,C)) -> Bool {
if lhs.0 != rhs.0 { return lhs.0 < rhs.0 }
if lhs.1 != rhs.1 { return lhs.1 < rhs.1 }
return lhs.2 < rhs.2
}

20 Swift Language Version Build Configuration
21 Naming Functions with Argument Labels
22 Referencing the Objective-C selector of a method

主要訴求:Selector 去 String 化。
Selector 去 String 化。
1
2
3
4
5
// Instead of this:
Selector("insertSubview:atIndex:")

// You'll use this:
let sel = #selector(((UIView.insertSubview(_:at:)) as (UIView) -> (UIView, Int) -> Void))

Proposals (Swift 2.2 已採用)

8 Add a Lazy flatMap for Sequences of Optionals


Proposals (Swift 3 已實現)

3 Removing var from Function Parameters
5 Better Translation of Objective-C APIs Into Swift
6 Apply API Guidelines to the Standard Library
19 Swift Testing
23 同6 API Design Guidelines
28 Modernizing Swift’s Debugging Identifiers
31 Adjusting inout Declarations for Type Decoration
34 Disambiguating Line Control Statements from Debugging Identifiers
37 Clarify interaction between comments & operators
40 Replacing Equal Signs with Colons For Attribute Arguments
43 Declare variables in ‘case’ labels with multiple patterns
53 Remove explicit use of let from Function Parameters

Proposals (Swift 3 已採用)

2 Removing currying func declaration syntax
4 Remove the ++ and -- operators
7 Remove C-style for-loops with conditions and incrementers
16 Add initializers to Int and UInt to convert from UnsafePointer and UnsafeMutablePointer
29 Remove implicit tuple splat behavior from function applications
33 Import Objective-C Constants as Swift Types
35 Limiting inout capture to @noescape contexts
38 Package Manager C Language Target Support
39 Modernizing Playground Literals
42 Flattening the function type of unapplied method references
44 Import as member
46 Establish consistent label behavior across all parameters including first labels
47 Defaulting non-Void functions so they warn on unused results
54 Abolish ImplicitlyUnwrappedOptional type
55 Make unsafe pointer nullability explicit using Optional

Swift org

before
1
2
3
4
class UIBezierPath : NSObject, NSCopying, NSCoding { ... }
///...
path.addLineToPoint(CGPoint(x: 100, y: 0))
path.fillWithBlendMode(kCGBlendModeMultiply, alpha: 0.7)
after
1
2
3
4
class UIBezierPath : Object, Copying, Coding { ... }
//...
path.addLineTo(CGPoint(x: 100, y: 0))
path.fillWith(kCGBlendModeMultiply, alpha: 0.7)