ios - declaring a global function across all views -


i have function eg. have across views in app. how go defining that. should function written.

read somewhere here 1 possible solution define function uiviewcontroller extension so:

extension uiviewcontroller {     func displayalert(title:string, error:string, buttontext: string) {     ...    } } 

where should such procedure declared?

thanks

create new swift file , name like: uiviewcontroller+displayalert.swift

in there can add code in question.

extension uiviewcontroller {     func displayalert(title:string, error:string, buttontext: string) {     ...    } } 

since extending uiviewcontroller, you'll able access function on subclasses of uiviewcontroller.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -