Ambiguous type name error

筅森魡賤 提交于 2019-12-04 03:47:48

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/30377468/ambiguous-type-name-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!