簡體   English   中英

在目標中,類不止一次鏈接

[英]Class are being linked more than once in target

我有兩個目標appappTests 我還有類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子類不能在同一目標中包含兩次。 請確保'Wine'僅與您當前的目標相關聯一次。

我已經清楚了DerivedData和項目。 你能建議我應該在哪里看嗎?

在nhgrif評論之后編輯

好吧,看起來事先在第7行中出現了異常。現在由於nhgrif而在代碼中標記了。

Wine.swift應該只在app ,而不是appTests 將它包括在兩個結果中的appTests有兩個名為Wine類( app.WineappTests.Wine ),這不是Realm支持的。 只要Winepublic (或者在Swift 2.0, @Testable ),您可以從appTests訪問它而不將其包含在appTests目標中,因為app appTests鏈接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM