Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble: 'PrincipalViewController' does not have a member named 'revealViewController' in swift

I am working on a creating a sidebar menu using SWRevealViewController in Swift. Trouble is I get the following error: 'PrincipalViewController' does not have a member named 'revealViewController'

The code I am working on is:

class PrincipalViewController: UIViewController {
@IBOutlet weak var menuButton:UIBarButtonItem!

override func viewDidLoad() {
    super.viewDidLoad()

    // This is the line with the error
    if self.revealViewController() != nil {

        menuButton.target = self.revealViewController()
        menuButton.action = "revealToggle:"
        self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())

        // Uncomment to change the width of menu
        //self.revealViewController().rearViewRevealWidth = 62
    }

}

Any ideas? Thanks a lot

like image 675
Jesús Guerrero Almaraz Avatar asked Mar 05 '15 08:03

Jesús Guerrero Almaraz


3 Answers

I just found the problem. There is son objective-c code in the app, and the bridging header was not well configured. Thanks a lot

like image 153
Jesús Guerrero Almaraz Avatar answered Sep 28 '22 17:09

Jesús Guerrero Almaraz


As of Cocoapods >0.36, if you're using Cocoapods to add SWRevealViewController to your project, don't mess with the bridging header. Just uncomment use_frameworks! in your Podfile. Then import SWRevealViewController into your ViewController.swift file. Here's a great article that explains it.

like image 28
jkw224 Avatar answered Sep 28 '22 16:09

jkw224


To clear this up for others who do not understand the answer's explanation... Make sure the Bridging header file is connected to the Path of the Objective C Bridging Header which is found in the Swift Compiler found in Build Settings of your project...

Here is a link for the way to check if it is there, look under adding it manually for a picture as well...

http://www.learnswiftonline.com/getting-started/adding-swift-bridging-header/

like image 30
Lion789 Avatar answered Sep 28 '22 17:09

Lion789