iOS Developer

2017WWDC whats new in swift

2017-06-28  本文已影响56人  雨_树

Swift关键字 Open Source + Growing Ecosystem

Language refinements and additions

Access Control
"private": 作用域变为可在"extension"中访问

Composing Classes and Protocols

"class"和"protocol"可以组合起来使用

protocol Shakeable {
    func shake()
}
extension UIButton: Shakeable { /* … */ }
extension UISlider: Shakeable { /* … */ }
func shakeEm(controls: [UIControl & Shakeable]) {
    for control in controls where control.state.isEnabled {
        control.shake()
    }
}

Reference
Section What's New in Foundation

Source compatibility

Swift 4 largely source-compatible with Swift 3
这次总算是向前兼容Swfit 3了: Swift 3 和 Swift 4可以共存在同一个项目中

Swift Version
可以对Target单独设定Swift的版本,但是对我们这种只有单独Target的产品而言,还是只能支持一种啊?

Tools and performance

Build Improvements

新的编译系统提供更快的编译速度,特别是对于大的项目

"Precompiled Bridging Headers": 在OC/Swift混合代码中桥接头文件会很慢,使用预编译可以有效的加快编译时间

"Shared Build for Coverage Testing": XCode9不再需要重新编译

"Indexing While Building": 避免"Background indexing"的重复工作,在编译的过程中直接更新"index"

Predictable Performance

"COW Existential Buffers": Copy-On-Write,只有在修改时才拷贝,避免昂贵的堆Heap分配消耗

"Faster Generic Code": 在使用泛型Generic时,用Stack取代Heap进行栈分配

Smaller Binaries

Swift 4 会自动移除未被使用的代码

"Limited @objec Inference"

"Symbol Size"

Standard library

Swift Strings

Swift: A Character is a grapheme

"Simpler one-sided Slicing Syntax"

"Substrings"

"Multi-line String Literals"

New Generics Features

where closure in the associatetype

Generic Subscript

Exclusive access to memory

Non-Exclusive Access to Memory

无法控制混乱的访问,以及可能导致的性能问题

Enforcing Exclusive Access to Memory

Swift 4只允许同时读操作

Run-time Enforcement

Multi-threaded Enforcement

设置

上一篇 下一篇

猜你喜欢

热点阅读