Build a slide-out sidebar menu in iOS using the Objective-C library SWRevealViewController with a bridging header and Swift extensions. SWRevealViewController is an Objective-C container view controller that manages a front content view and a rear menu view. You create an Objective-C bridging header to expose the library to Swift. Swift extensions wrap the Objective-C API for clean Swift usage. The library provides gesture recognizers and built-in segues for menu navigation.
What Is SWRevealViewController and How Does It Work?
SWRevealViewController is a container view controller that manages two child view controllers. The front view controller displays the main content. The rear view controller displays the navigation menu. Users reveal the menu by swiping right or tapping a hamburger button.
The library supports left and right sidebars. It provides gesture recognizers for swipe-to-open behavior. It includes built-in segues for menu item navigation. SWRevealViewController is written in Objective-C, which requires a bridging header to use from Swift.
How to Add SWRevealViewController to a Swift Project
Add the SWRevealViewController source files to your project. Download SWRevealViewController.h and SWRevealViewController.m from the GitHub repository. Create a group named SWRevealViewController in Xcode. Drag both files into the group.
When Xcode prompts, create an Objective-C bridging header. Xcode generates a file named ProjectName-Bridging-Header.h. Open this file and import the library.
// ProjectName-Bridging-Header.h
#import "SWRevealViewController.h"
The bridging header exposes all public Objective-C interfaces to Swift. Every Objective-C class, method, and property becomes available with its original name.
How to Configure SWRevealViewController in Storyboard
Set the container view controller's class to SWRevealViewController in the Identity inspector. Wire up the rear and front view controllers using custom segues with specific identifiers.
Control-drag from the SWRevealViewController to the menu controller. Select reveal view controller set controller. Set the segue identifier to sw_rear. Control-drag from the SWRevealViewController to the front navigation controller. Select reveal view controller set controller. Set the segue identifier to sw_front.
The sw_rear identifier designates the rear controller. The sw_front identifier designates the front controller. These identifiers are required by SWRevealViewController.
How to Implement the Sidebar Toggle in Swift
Connect the hamburger menu button to the revealToggle action. Add the pan gesture recognizer for swipe-based opening.
override func viewDidLoad() {
super.viewDidLoad()
guard let revealVC = revealViewController() else { return }
menuButton.target = revealVC
menuButton.action = #selector(SWRevealViewController.revealToggle(_:))
view.addGestureRecognizer(revealVC.panGestureRecognizer())
}
The revealToggle method toggles the sidebar open and closed. The panGestureRecognizer enables swipe gestures anywhere on the content view.
How to Handle Menu Item Navigation
Use custom reveal view controller push controller segues in storyboard. Control-drag from each menu cell to the corresponding content view controller's navigation controller. Select reveal view controller push controller under Selection Segue.
This custom segue replaces the front view controller when the user taps a menu item. The sidebar automatically closes after selection. No additional code is needed.
How to Customize Sidebar Appearance and Behavior
SWRevealViewController provides configurable properties for sidebar width, bounce effects, and gesture control.
guard let revealVC = revealViewController() else { return }
revealVC.rearViewRevealWidth = 260
revealVC.bounceBackOnOverdraw = false
revealVC.quickFlickVelocity = 5.0
rearViewRevealWidth sets the visible width of the sidebar when open. bounceBackOnOverdraw controls the rubber-band effect when swiping beyond the sidebar width. quickFlickVelocity adjusts the swipe speed threshold for automatic opening.
How to Add a Right Sidebar
SWRevealViewController supports a right sidebar in addition to the left menu. Set sw_right segue identifier in storyboard. Use rightRevealToggle for activation.
rightButton.target = revealVC
rightButton.action = #selector(SWRevealViewController.rightRevealToggle(_:))
revealVC.rightViewRevealWidth = 200
The rightRevealToggle method works identically to revealToggle but controls the right sidebar. Configure rightViewRevealWidth to set the right sidebar width.
How to Wrap SWRevealViewController with Swift Extensions
Isolate the Objective-C dependency by creating a UIViewController extension. This keeps view controller code clean and makes the sidebar setup reusable across multiple view controllers.
extension UIViewController {
func addSidebarMenu(leftButton: UIBarButtonItem? = nil, rightButton: UIBarButtonItem? = nil) {
guard let revealVC = revealViewController() else { return }
if let leftButton = leftButton {
leftButton.target = revealVC
leftButton.action = #selector(SWRevealViewController.revealToggle(_:))
}
if let rightButton = rightButton {
rightButton.target = revealVC
rightButton.action = #selector(SWRevealViewController.rightRevealToggle(_:))
revealVC.rightViewRevealWidth = 200
}
view.addGestureRecognizer(revealVC.panGestureRecognizer())
}
}
Each view controller now calls addSidebarMenu in viewDidLoad instead of repeating setup code.
override func viewDidLoad() {
super.viewDidLoad()
addSidebarMenu(leftButton: menuButton, rightButton: rightButton)
}
Practical Tips for Objective-C Library Integration
Use the bridging header for Objective-C imports. Only import headers that your Swift code directly references.
Prefer Swift extensions to wrap Objective-C APIs. Extensions isolate the dependency and create a clean Swift interface.
Use #selector with the full type name for Objective-C methods. The syntax is #selector(ClassName.methodName). This avoids ambiguous selector warnings.
Test gesture controls on physical devices. The simulator does not accurately reproduce swipe sensitivity and gesture conflicts.
Consider accessibility. The hamburger menu pattern hides navigation from discoverability. Provide clear visual indicators and VoiceOver labels.
Summary
This tutorial covered the complete implementation process from setup to working code. You now have a functional implementation that you can extend and customize for your own projects. The same patterns apply to related features in the iOS ecosystem.
Frequently Asked Questions
What Xcode version do I need for this tutorial? This tutorial uses Xcode 26 with Swift 6.2. The code examples work with any recent version of Xcode that supports the frameworks used here.
Can I test this on the iOS Simulator? Some features require a physical device with a compatible processor. The article notes specific sections where the Simulator is sufficient and where a real device is required.
What are the prerequisites for this tutorial? You need Xcode installed on a Mac and basic familiarity with Swift programming. No prior experience with the specific framework is required.