SWRevealViewController from the right side on swift

Ilir V. Gruda picture Ilir V. Gruda · May 20, 2015 · Viewed 10k times · Source

I am using SWRevealViewController library to make a slide out menu in swift, but I am struggling to put this menu in the right side. I have seen on the library description this comment

// Optional right view controller, can be nil if not used
@property (nonatomic) UIViewController *rightViewController;

but I am not familiar with objective C and I am not being able to do this on swift. This is a part of my code for the default(left) menu:

class ViewController: UIViewController, AVAudioPlayerDelegate {

@IBOutlet weak var playlistOutlet: UIBarButtonItem!

override func viewDidLoad() {
    super.viewDidLoad()

    playlistOutlet.target = self.revealViewController()
    playlistOutlet.action = Selector("revealToggle:")

    self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())

}
}

And revealViewController is called from the SWRevealViewController library

Answer

Michael K. picture Michael K. · Sep 10, 2015

I followed this solution, in the controller of the front siding view use this:

override func viewDidLoad() {
    super.viewDidLoad()

    if self.revealViewController() != nil {
        favoritesButton.target = self.revealViewController()
        favoritesButton.action = "rightRevealToggle:"
        self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
    }
}

Don't forget to create the Outlet to the item bar button first. In the storyboard, set the segue value to sw_right

Xcode 7 Beta 6 Screenshot

And first that didn't work for me, but a clean helped.