Last active
June 1, 2021 09:23
-
-
Save kyungpyoda/16d932a25121a154afebc83524a6ad44 to your computer and use it in GitHub Desktop.
[Swift] view controller going back extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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