Avoiding the Overuse of @objc in Swift
Swift 2.2’s #selector
syntax introduces a new compiler error:
Argument of '#selector' refers to a method that is not exposed to Objective-C. Fix-it Add '@objc' to expose this method to Objective-C
We cannot simply add
@objc
to this method in the originalViewControllerType
protocol for a number of reasons. If we do, then the entire protocol needs to be marked@objc
, which means[…] Our example here is simple, but imagine a much more complex object graph that makes heavy use of Swift’s value types and a hierarchy of three protocols with this one in the middle. Introducing@objc
as the fix-it suggests would break the entire world in our app.[…]
We can decompose this protocol by separating out all of the
@objc
code into its own protocol. Then, we can use protocol composition to reunite them.