iOS/Swift

[UIKit] ๊ฐ„๋‹จํ•œ toast message, ํ™•์ธ ๋ฒ„ํŠผ๋งŒ ์žˆ๋Š” alert ์˜ˆ์ œ

extension UIViewController {
    func alert(_ message: String, completion: (()->Void)? = nil) {
        DispatchQueue.main.async {
            let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert)
            let okAction = UIAlertAction(title: "ํ™•์ธ", style: .cancel) { (_) in
                completion?()
            }
            alert.addAction(okAction)
            self.present(alert, animated: false)
        }
    }
}

์‚ฌ์šฉํ•  ๋•Œ์—๋Š” ์•„๋ฌด๋ฐ์„œ๋‚˜

self.alert("์•Œ๋ฆผ๋ฉ”์‹œ์ง€!!!")

 ์ด๋ ‡๊ฒŒ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค ๐Ÿ˜Ž