ios - Swift Displaying Alerts best practices -


i have various controllers in app require validation, , when validation fails, want display alert errors. there best practice/design pattern doing this? create static function in helper class so:

static func displayalert(message: string, buttontitle: string, vc: uiviewcontroller) {     let alertcontroller = uialertcontroller(title: "", message: message, preferredstyle: .alert)      let okaction = uialertaction(title: buttontitle, style: .default, handler: nil)     alertcontroller.addaction(okaction)      vc.presentviewcontroller(alertcontroller, animated: true, completion: nil) } 

but need pass view controller..which seems bad practice. shoot off notification , observe it, seems overkill. overthinking this, or there more acceptable way go handling this?

i ended creating extension uiviewcontroller , creating alert function there:

extension uiviewcontroller {    func alert(message: string, title: string = "") {     let alertcontroller = uialertcontroller(title: title, message: message, preferredstyle: .alert)     let okaction = uialertaction(title: "ok", style: .default, handler: nil)     alertcontroller.addaction(okaction)     self.presentviewcontroller(alertcontroller, animated: true, completion: nil)   }  } 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -