I am writing an application in swift and using singleton to share an object of the User class in the application. I want this singleton to be set to "nil" when the user logs out, so that when they return to the old properties, it no longer exists (for example, name, username, etc.). I hope there is an easy way to just set singleton back to zero, instead of setting each property to nil.
Here is my User class, which is used in the application as User.activeUser:
class User: NSObject { class var activeUser : User? { struct Static { static let instance : User = User() } return Static.instance } }
How can I change this so that the code below does not give me a warning and actually deduces a singleton object from it:
User.activeUser = nil
source share