私の問題は、アプリケーションのほとんどのクラスで使用されている定数クラスだから、AppDelegateでそのオブジェクトを作成しました。それから、them.iにアクセスしたいオブジェクトを作成したくありません。毎回どこの定数の。何が最良のアプローチアドバイスをしてください。AppDelegateの参照を取得する方法
class AppDelegate: UIResponder, UIApplicationDelegate {
public var constants = Constants()
//created object once in app delegate
}
class Utility
{
let delegate = UIApplication.shared.delegate as! AppDelegate //getting null here
let constants = delegate. constants
}`
'UIApplicationDelegate'はすでに一意のインスタンスです。そのコピーを作成しないでください。その参照を使用してください。 –
[Swiftのアプリケーションデリゲートへの参照を取得するにはどうすればよいですか?](http://stackoverflow.com/questions/24046164/how-do-i-ja-reference-to-the-app-代理 - イン - スウィフト) – Vinodh
複製の質問を追加する前にそれを検索 – Vinodh