EzDevInfo.com

SwiftyUserDefaults

Statically-typed NSUserDefaults Statically-typed NSUserDefaults • radex.io

Ambiguous type name error

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?


Source: (StackOverflow)