<分区>
我有应用程序委托(delegate),它是应用程序中的一个点。我还创建了 ApplicationManager
类,它现在是应用程序委托(delegate)的一部分。
所以我想要实现的是保护我的代码不被其他开发人员以错误的方式使用。
假设我的 ApplicationManager
看起来像这样:
class ApplicationManager {
var api: API?
static func instance() -> ApplicationManager {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
fatalError()
}
return appDelegate.applicationManager
}
}
我想确保 used 将通过以下方式使用 ApplicationManager:
让 am = ApplicationManager.instance()
但不要像这样 am = ApplicationManager()
那样会再创建一个我不想要的管理器。
有没有办法显示构建时间错误?或删除一些消息?或在应用程序中有多个 ApplicationManager
时崩溃崩溃 =)