我有一个主类,AddFriendsController它运行以下代码行:
ErrorReporting.showMessage("Error", msg: "Could not add student to storage.")
Run Code Online (Sandbox Code Playgroud)
然后我有这个ErrorReporting.swift文件:
进口基金会
class ErrorReporting {
func showMessage(title: String, msg: String) {
let alert = UIAlertController(title: title, message: msg, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
显然,self不会在这里工作,并给我一个错误.我如何引用当前打开的视图控制器(即AddFriendsController在这种情况下),因为我希望在许多不同的swift文件中使用相同的方法?
谢谢.