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

3

6

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

Godmother answered 5/3, 2015 at 8:20 Comment(4)
What is self.revealViewController()?Memphian
I think is the view controller for the side bar. But I did a search in the demo app that is working and there is no reference to that viewImmorality
This is the site where I downloaded the code (appcoda.com/sidebar-menu-swift)Immorality
So why are you using () after the property?Memphian
G
5

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

Godmother answered 5/3, 2015 at 9:1 Comment(0)
M
5

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.

Mancino answered 30/11, 2015 at 16:28 Comment(0)
D
2

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/

Dazzle answered 22/8, 2015 at 17:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.