Class 在目标中被链接了不止一次

Class are being linked more than once in target

我有两个目标 appappTests。我还有 class Wine 和框架 Realm 和 'RealmSwift' 与这两个目标相关联。当我在 traget app 中使用 class Wine 时也不例外。

但是当我想 运行 像

那样测试时

appTests.swift(22 行)

import UIKit
import XCTest
import RealmSwift

class appTests: XCTestCase {
func testRealmAdd() {
         NSFileManager.defaultManager().removeItemAtPath(Realm.defaultPath, error: nil)
        let realm = Realm()
        let wine = Wine() // when error occure
        wine.photo = "photo"
        wine.desc = "description"
        wine.raiting = 3.0

        realm.write { () -> Void in
            realm.add(wine)
        }

        let result = realm.objects(Wine)
        print("\(result)")
        XCTAssertTrue(result.count == 1, "There should be one element")
    }
}

Wine.swift(10 行)

import UIKit
import RealmSwift

class Wine: Object {

    dynamic var desc: String = ""
    dynamic var photo: String = ""
    dynamic var raiting: Double = 0

}

然后appTests.swift

第8行出现异常

RLMObject subclasses with the same name cannot be included twice in the same target. Please make sure 'Wine' is only linked once to your current target.

我已经清除了 DerivedData 和项目。你能建议我应该去哪里看吗?

在 nhgrif 评论后编辑

好的,似乎在第 7 行出现了一个异常。感谢 nhgrif,现在已在代码中标记出来。

Wine.swift 只应在 app 中,而不应在 appTests 中。将它包含在两者中会导致 appTests 有两个 类 命名为 Wineapp.WineappTests.Wine),这不是 Realm 支持的。只要 Winepublic(或在 Swift 2.0、@Testable 中),您就可以从 appTests 访问它而无需将其包含在 appTests 目标是因为 appTests 链接在 app.