波肥來介紹 Swift 的 method dispatch。
{ 完整節目筆記 https://weakself.dev/episodes/70) }
👋開場
⏪上集節目回顧 聽眾 dan12411 貢獻他的 Xcode 技巧。
📰一週開發者新聞
🧪Xcode 12.5 beta 3 & iOS 14.5 beta 3
⭐️Swift Runtime 1—Method Dispatch in Swift/ObjC: Static, Table, Message Dispatch
struct 的 func 一定是 static dispatch。因為 optimization 設定的不同,有可能會是 inline
class 的 func 通常是 table dispatch。如果加了 final 或是在 extension 定義新 func 就會是 static。
Swift 裡的NSObject subclass,一般 func 也是 table dispatch,即使加了 @objc 也一樣。若是 @objc dynamic就會是 message dispatch。如果加了 final 就會是 static
想要自行研究的話,可以用以下方法(程式碼請見完整節目筆記))
用 swiftc -emit-silgen Foo.swift -Onone 即可得到 SIL
💸勸敗話題
👋收尾
更多 weak self
聽眾信箱 [email protected]
Twitter @weak_self)
提問箱)
-- Hosting provided by SoundOn)