What's the difference between marking a method as @o...
What's the difference between marking a method as @o...
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[1][5]. This is required for features like key-value observing to work correctly[1].
dynamic tells the Swift compiler to always use Objective-C dynamic dispatch for the method, rather than static or virtual dispatch[1][2]. This is necessary if you plan to modify the method implementation at runtime using the Objective-C runtime[2].
In Swift 4 and later, dynamic no longer implies @objc - you must explicitly use @objc dynamic to get both Objective-C visibility and dynamic dispatch[2][3].
You would use @objc when:
expert