Hi all I'm trying to implement KVO on one of the string properties within a Singleton class. I'm currently running into some errors when trying to add an observer and was hoping that someone could tell me what I'm doing wrong. The below shows my singleton class.
class User: NSObject {
static let currentUser = User()
private override init() {}
var pictureString: String?
}
In a separate ViewController's viewDidLoad, I've tried to add an observer to the pictureString variable like so.
self.addObserver(self, forKeyPath: #keyPath(User.currentUser.pictureString), options: [.old, .new, .initial], context: nil)
the problem I'm dealing with right now is that it is stating that currentUser is not KVC-compliant. I'm currently getting the below error.
addObserver: forKeyPath:@"currentUser.pictureString" options:7 context:0x0] was sent to an object that is not KVC-compliant for the "currentUser" property.'
I'd appreciate any help thanks.