【问题标题】:Class implemented in app target and test target在应用程序目标和测试目标中实现的类
【发布时间】:2018-07-31 07:49:58
【问题描述】:

我正在使用 CoreData,并通过返回来自 CocoaPods 依赖项的类对象的自定义变量扩展了自动(未生成自定义类文件)模型类。

import Foundation
import ACocoaPodsFramework
import CoreData

extension MyClass {
    var customVar: AClassFromCocoaPods? {
        return AClassFromCocoaPods()
    }
}

我已将单元测试目标添加到 Xcode 项目,并将 MyClass 和 xcdatamodeld 添加到测试目标。一个测试类如下所示。

import XCTest
import ACocoaPodsFramework
import CoreData
@testable import MyAppTarget

class MyClassTests: XCTestCase {
}

我在应用程序和单元测试目标中都导入了 ACocoaPodsFramework 作为框架。

当我运行单元测试时,我会收到以下通知

objc[21178]: Class MyClass is implemented in both /.../MyAppTarget.app/MyAppTarget (0x1017703f0) and /... MyAppTarget.app/PlugIns/MyClassTests.xctest/MyClassTests (0x123dc8ae8). One of the two will be used. Which one is undefined.

和例外

Could not cast value of type 'MyAppTarget.MyClass' (0x60c0000ccc60) to 'MyAppTargetTests.MyClass' (0x1258c9a20).

【问题讨论】:

  • 您是只看到此警告还是也收到任何错误?
  • 我在问题中添加了例外

标签: swift xcode core-data cocoapods


【解决方案1】:

通过从测试目标中删除 所有 应用程序文件并使用

在测试类中导入所需的应用程序文件来解决此问题
@testable import MyAppTarget

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多