내 응용 프로그램에 여러 개의보기 컨트롤러가 있습니다. 그리고 그들 각각에서 나는 어떤 조건들에 기초하여 경고를 보여 주어야합니다. 각각에 경고 컨트롤러를 추가하는 대신 다음과 같이 상속을 시도했습니다.UIViewController 및 상속
UIExtension.swift
class UIExtension: UIViewController {
func prepareAlert(title: String, message: String) -> UIAlertController {
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
return alert
}
}
FirstViewController.swift 경보를 표시하기 위해 다른 viewcontrollers에 UIExtension 사용 마찬가지로
class FirstViewController: UIExtension {
//somewhere inside used the following
present(prepareAlert(title: "Error Validation", message: "invalid fields"), animated: true, completion: nil)
}
. 이 방법이 권장됩니까?