I'm trying to re-compile SwiftyUserDefaults(https://github.com/radex/SwiftyUserDefaults) to add Carthage support, but on attempt to compile I see following error:
Ambiguous type name 'Proxy' in 'NSUserDefaults'
for following code
public func ?= (proxy: NSUserDefaults.Proxy, @autoclosure expr: () -> Any) {
if !proxy.defaults.hasKey(proxy.key) {
proxy.defaults[proxy.key] = expr()
}
}
and
'Proxy' is ambiguous for type lookup in this context
for
public subscript(key: String) -> Proxy {
return Proxy(self, key)
}
As I understand - problem is with class Proxy, that's embedded in extension.
public extension NSUserDefaults {
class Proxy {
private let defaults: NSUserDefaults
private let key: String
private init(_ defaults: NSUserDefaults, _ key: String) {
self.defaults = defaults
self.key = key
}
// MARK: Getters
public var object: NSObject? {
return defaults.objectForKey(key) as? NSObject
}
// ..................................
}
}
I've looked for documentation, but there isn't any reference that a class can be used in extension.
Is it right?
You are compiling the SwiftlyUserDefaults.swift
file twice in your target SwiftlyUserDefaultsTests: once in the SwiftlyUserDefaults.framework
(which is a dependency of SwiftlyUserDefaultsTests), and once in the "Compile Source" build phase.
Just remove the SwiftlyUserDefaults.swift
file from the "Compile Source" build phase of your SwiftlyUserDefaultsTests target and you should be good to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With