Framework updates
Performance update
Scrolling
在一個cellForRow()
裡面,主要會做Dequeue 與config cell 這兩個動作,config cell 所消耗的時間完全取決於App 對於該List 設計的複雜度而決定,在進行玩這兩個動作,系統會對UITableViewCell 內的UIView 進行layoutSubview()
與draw()
,這些動作通通必須在16 ms 內做完,如果是在120 Hz 的裝置(如iPad Pro),你就只剩下8 ms,否則就得掉Frame。
Config cell 內,若有一些資料準備的事情,則可透過prefetch API 來進行效能改善,但必須注意的是Prefetch API 並不支援所有版本iOS。(如果用IGListKit 就更方便了,我們有Display delegate 跟Working range)
大致上的改動在於,UIKit 如何排程使得CPU 在prefetch 時,可以更加的有效率,在以前的版本,儘管是prefetch,他與cellForRow()
可以說是在同一個時間點做,CPU 的loading 並不會因此而降低,所以掉Frame 的狀況還是會發生。
Memory
Automatic Backing Store 會自動壓縮圖片的內容,CoreGraphic 會自動做到這點在以下幾種狀況:
UIView.draw()
UIGraphicsImageRenderer
UIGraphicsImageRendererFormat.Range
可惜細節的部分並沒有提太多,也不知道效果如何。
Auto layout
在iOS 12 當中,Auto layout 的演算法被優化,在預設的狀況下,效能將從獲得改善。
相關議程:High Performance Auto Layout
Swiftification
Apple 希望使用UIKit 時可以更加的feel like Swift,如:
// Swift 4
enum UIApplicationState {
case active
case inactive
case background
}
// Swift 4.2
class UIApplication: UIResponder {
enum State {
case active
case inactive
case background
}
}
let insets = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0)
let image = UIImage(named: "Apple")
// Swift 4
let insetRect = UIEdgeInsetsInsetRect(originalRect, insets)
let pngData = UIImagePNGRepresentation(image)
// Swift 4.2
let insetRect = originalRect.insetBy(insets)
let pngData = image.pngData()
API enhancement
Notification
- interaction – 可以有更多的互動,有點類似小小的獨立程式
- Grouping – 相同App 的notification 將會被放在一起
- Setting – 提供API 來設定notification 相關的新設定
Message
Password Auto Fill
可以透過messages 拿到驗證碼來填入App 的表單當中
相關議程:Automatic Strong Passwords and Security Code AutoFill
Safe Area
Siri shortcut
一個全新的API 讓App 可以透過NSUserActivity
與Intents
來支援Siri 操作你的App,SiriKit
當中的Intents 裡面包含許多預設的API,這次也可以實作Custom intents。
相關議程:Introduction to Siri Shortcuts、Building to voice with Siri Shortcuts、Siri Shortcuts on the Siri Watch Face