I am trying to mock NSUserDefaults in Swift to be able to create tests on classes that use the NSUserDefaults. Now I run into a problem because the Proxy has no public initializer and I cannot overwrite it. I cannot use the regular proxy either because its initializer is private and cannot be used outside the scope of the nesting class.
Any ideas how to solve this? Any neat tricks that could help me to initialize the FakeProxy?
public class FakeProxy : NSUserDefaults.Proxy {
private let defaults: NSUserDefaults
private let key: String
public init(_ defaults: NSUserDefaults, _ key: String) {
self.defaults = defaults
self.key = key
// Problem: Super.init isn't called before returning from initializer
}
...
}
Aucun commentaire:
Enregistrer un commentaire