模糊类型名称错误 [英] Ambiguous type name error
问题描述
我正在尝试重新编译SwiftyUserDefaults( https://github.com/radex/SwiftyUserDefaults)添加Carthage支持,但在尝试编译时我看到以下错误:
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:
'NSUserDefaults'中的不明确的类型名称'Proxy' / p>
Ambiguous type name 'Proxy' in 'NSUserDefaults'
以下代码
public func ?= (proxy: NSUserDefaults.Proxy, @autoclosure expr: () -> Any) {
if !proxy.defaults.hasKey(proxy.key) {
proxy.defaults[proxy.key] = expr()
}
}
和
'代理'在此上下文中的类型查找不明确
'Proxy' is ambiguous for type lookup in this context
for
public subscript(key: String) -> Proxy {
return Proxy(self, key)
}
据我所知 - 问题在于类Proxy,它是嵌入在扩展中的。
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.
是不是?
推荐答案
您正在编译 SwiftlyUserDefaults.swift
文件两次在目标SwiftlyUserDefaultsTests中:一次在 SwiftlyUserDefaults.framework
(这是SwiftlyUserDefaultsTests的依赖项),以及一次进入编译源构建阶段。
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.
从编译源中删除 SwiftlyUserDefaults.swift
文件你的SwiftlyUserDefaultsTests目标的构建阶段,你应该好好去。
Just remove the SwiftlyUserDefaults.swift
file from the "Compile Source" build phase of your SwiftlyUserDefaultsTests target and you should be good to go.
这篇关于模糊类型名称错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!