arrays - 运行 XCTests 时出现 "Ambiguous use of ' MYFUNCTION( )'"错误

标签 arrays swift xctest

我在尝试运行 XCTests 时遇到多个函数错误。

例如,我有一个简单的数组扩展来提取唯一的数组:

public extension CollectionType where Generator.Element: Hashable {
    /// Returns the collection with duplicate values in `self` removed.
    var unique: [Generator.Element] {
        get {
            var seen: [Generator.Element:Bool] = [:]
            return self.filter { (element) -> Bool in
                return seen.updateValue(true, forKey: element) == nil
            }
        }
    }
}

但是在测试中,当我尝试使用它时遇到错误:

Ambiguous use of 'unique'

有什么解决办法吗?

最佳答案

我发现我的问题是我的 swift 文件包含在我的框架目标和 XCTest 目标中(因此编译器看到该文件包含了两次,导致了歧义)。从测试目标中删除它修复了错误。希望这对其他人(或 future 的我)有所帮助。

关于arrays - 运行 XCTests 时出现 "Ambiguous use of ' MYFUNCTION( )'"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34726595/

相关文章:

arrays - Angular2, typescript :How to push array of objects into another array of objects with only a few fields of the object

objective-c - 在我的 Swift 应用程序中使用来 self 的 XPC 服务的 Objective-C 协议(protocol)

xcode - swift - MacOs 应用程序 - 添加到 finder 上下文菜单?

ios - cocoapod 中缺少框架

java - (Java) 使用二维数组的 Tic-Tac-Toe 游戏

c - 我在生成随机数时遇到问题 (C)

来自数组的 JavaScript 函数

ios - XCTests 在物理设备上失败 : "Canceling tests due to timeout ..."

ios - Swift - 使用 XCTest 测试包含闭包的函数

ios - 不同UIApplicationMain时引用appDelegate