我想编写一个函数alert()并运行它。但我想在不重复代码的情况下在任何Controller中显示此警报。例如:我有Presence.swift类,这里我有一些条件,如:ifmyVar==1{//JustforpresentingrunMyAlert()}当myVar==1用户处于后台时,无论他身在何处,在哪个屏幕上,他都会在屏幕上收到警报。如何在不重复我的代码的情况下做到这一点?我试图在AppDelegate中将其制作为:funcalert(title:String,message:String,buttonTitle:String,window:UIWindow){letalert