Skip to content

Instantly share code, notes, and snippets.

@kyungpyoda
Last active June 1, 2021 09:23
Show Gist options
  • Save kyungpyoda/16d932a25121a154afebc83524a6ad44 to your computer and use it in GitHub Desktop.
Save kyungpyoda/16d932a25121a154afebc83524a6ad44 to your computer and use it in GitHub Desktop.
[Swift] view controller going back extension
//
// UIViewController+back.swift
//
// Created by 홍경표 on 2021/06/01.
//
// TODO: `addTarget` to a button
// backButton.addTarget(nil, action: #selector(back), for: .touchUpInside)
extension UIViewController {
@objc func back() {
if self.presentingViewController != nil {
self.dismiss(animated: true, completion: nil)
} else {
self.navigationController?.popViewController(animated: true)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment