Search code examples
iosios11swift4uirefreshcontrol

How to avoid using @objc with a refresh control in iOS 11 with Swift 4?


I upgraded my project from Swift 3 to Swift 4 and during the migration it inserted a bunch of '@objc' annotations in my code. I wish to get rid of them to avoid generating any Objective-C entry points. One of the ones I can't figure out how to get rid of, is using the refresh control. Here is the offending code:

let refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: #selector(MyController.handleRefresh(refreshControl:)), for: .valueChanged)
self.table.refreshControl = refreshControl;

The problem is the use of the #selector it seems. How can I implement my refresh control without a selector?


Solution

  • I wish to get rid of them

    You can't, and you need to stop wanting to. #selector is an Objective-C feature and therefore you must explicitly expose the action method to Objective-C. (Previously you were already exposing it implicitly; now you must say what you mean.)