vendredi 8 avril 2016

Trigger lazy initialization in swift

I have this code

class UserStatusController: NSObject {
    private static let sharedInstance = UserStatusController()

    private override init() {
        super.init()

        // some functionality
    }

    // some functionality
}

It seems like swift automatically made my sharedInstance variable lazy, and doesn't instantiate it since all interaction with this singleton is performed through NotificationCenter and object is not accessed directly from outside. The question is how can I trigger instantiation of my singleton except of adding some dummy method and calling it?

Aucun commentaire:

Enregistrer un commentaire