でオブジェクトを初期化に失敗しました:私はobj = MyObject()
をコメントアウトした場合にのみスウィフトは - 私は<code>Object</code></p> <pre><code>class MyObject: NSObject { // some properties override init() { super.init() // not to init other properties here print("MyObject init!") } } </code></pre> <p>と<code>Singleton</code>を持つシングルトン
class Singleton: NSObject {
static let sharedInstance = Singleton()
var obj: MyObject?
private override init() {
obj = MyObject()
print("obj init")
}
}
私のアプリが(obj init
は、印刷された)実行することができます。私がそれをコメントアウトしない場合、アプリは空白の画面で表示されますが、MyObject init
は印刷されません。
私に問題と解決方法を教えてください。
ありがとうございます。
- UPDATE -
私はdidFinishLaunchingWithOption
でobj
を初期化することができますまたは任意の他のViewControllerのviewDidLoad
:
private let singleton = Singleton.sharedInstance
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// FIXME: - This should be initialized in Singleton
singleton.obj = MyObject()
return true
}