Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build An iTunes Search App Building the User Interface Implementing a Search Bar

Argument of '#selector' refers to instance method 'dismissSearchResultsController()' that is not exposed to Objective-C

UPDATE: Found problem.

https://stackoverflow.com/questions/36818083/selector-refers-to-a-method-that-is-not-exposed-to-objective-c

@objc func dismissSearchResultsController() {
        self.dismiss(animated: true, completion: nil)
    }

Everything was going great for me up until this step. I can't seem to shake this error message and I'm not entirely sure where to start. I've checked file names, watched the video twice and this error keeps repeating.

import UIKit

class SearchResultsController: UITableViewController {



    override func viewDidLoad() {
        super.viewDidLoad()

        self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(SearchResultsController.dismissSearchResultsController))


    }

    func dismissSearchResultsController() {
        self.dismiss(animated: true, completion: nil)
    }

}

UPDATE: Found problem.

https://stackoverflow.com/questions/36818083/selector-refers-to-a-method-that-is-not-exposed-to-objective-c

@objc func dismissSearchResultsController() {
        self.dismiss(animated: true, completion: nil)
    }

1 Answer

Since #selector uses an underlying ObjC method we have to explicitly declare that in the dismiss SearchResultsController function.

@objc func dismissSearchResultsController() {
        self.dismiss(animated: true, completion: nil)
    }