Swift 3/4获取AppDelegate实例的引用

时间:2022-06-01 12:57:50

Swift 3/4获取AppDelegate实例:

func appDelegate() -> AppDelegate{
return UIApplication.shared.delegate as! AppDelegate
}

对于Swift < 3

func appDelegate() -> AppDelegate{
return UIApplication.sharedApplication().delegate as! AppDelegate
}