What's the difference between marking a method as @objc vs dynamic , when would you do one vs the other?
What's the difference between marking a method as @objc vs dynamic , when would you do one vs the other?
The main difference between marking a method as @objc vs dynamic in Swift is:
@objc exposes the method to the Objective-C runtime, allowing it to be called from Objective-C code. This is required for features like key-value observing to work correctly.
dynamic tells the Swift compiler to always use Objective-C dynamic dispatch for the method, rather than static or virtual dispatch. This is necessary if you plan to modify the method implementation at runtime using the Objective-C runtime.
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.