UIAlertController๋ฅผ ๋ง๋๋ extension
๐ parameters:
- title: ์๋ฆผ์ฐฝ์ ๋จ๋ ํ์ดํ ๋ถ๋ถ์
๋๋ค.
- message: ํ์ดํ ๋ฐ์ ๋จ๋ ๋ฉ์ธ์ง ๋ถ๋ถ์
๋๋ค.
- okAction: ํ์ธ๋ฒํผ์ ๋๋ ์ ๋ ๋์ํ๋ ๋ถ๋ถ์
๋๋ค.
- cancelAction: ์ทจ์๋ฒํผ์ ๋๋ ์ ๋ ๋์ํ๋ ๋ถ๋ถ์
๋๋ค.
- completion: ํด๋น UIAlertController๊ฐ ๋์์ก์ ๋, ๋์ํ๋ ๋ถ๋ถ์
๋๋ค.
extension UIViewController
{
func makeRequestAlert(title : String,
message : String,
okAction : ((UIAlertAction) -> Void)?,
cancelAction : ((UIAlertAction) -> Void)? = nil,
completion : (() -> Void)? = nil)
{
let generator = UIImpactFeedbackGenerator(style: .medium)
generator.impactOccurred()
let alertViewController = UIAlertController(title: title, message: message,
preferredStyle: .alert)
let okAction = UIAlertAction(title: "ํ์ธ", style: .default, handler: okAction)
alertViewController.addAction(okAction)
let cancelAction = UIAlertAction(title: "์ทจ์", style: .cancel, handler: cancelAction)
alertViewController.addAction(cancelAction)
self.present(alertViewController, animated: true, completion: completion)
}
func makeAlert(title : String,
message : String,
okAction : ((UIAlertAction) -> Void)? = nil,
completion : (() -> Void)? = nil)
{
let generator = UIImpactFeedbackGenerator(style: .medium)
generator.impactOccurred()
let alertViewController = UIAlertController(title: title, message: message,
preferredStyle: .alert)
let okAction = UIAlertAction(title: "ํ์ธ", style: .default, handler: okAction)
alertViewController.addAction(okAction)
self.present(alertViewController, animated: true, completion: completion)
}