Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 983
Alexey Poimtsev Avatar asked Oct 19 '22 11:10

Alexey Poimtsev


1 Answers

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.

enter image description here

like image 117
Guillaume Algis Avatar answered Oct 22 '22 01:10

Guillaume Algis