Dismiss a Modal UIViewController created in Interface Builder

There are a number of posts on this subject on Stack. They involve re-instantiating (this seems slower to me) or yanking the view from a UIButton (this feels dirty).

I’d rather just update the UIBarButtonItem that I already have:

2014-07-27_1826

All I needed to do, was attach the appropriate target and action to the UIBarButtonItem:

class SettingsTableViewController : UITableViewController {
    
    @IBOutlet weak var doneBarButton: UIBarButtonItem!
    
    init(coder aDecoder: NSCoder!) {
        super.init(coder: aDecoder)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        doneBarButton.target = self
        doneBarButton.action = "donePressed:"
    }
    
    @IBAction func donePressed(b:UIBarButtonItem) {
        self.dismissViewControllerAnimated(true, completion: {})
    }
}