[英]Class are being linked more than once in target
我有兩個目標app
和appTests
。 我還有類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.Wine
和appTests.Wine
),這不是Realm支持的。 只要Wine
是public
(或者在Swift 2.0, @Testable
),您可以從appTests
訪問它而不將其包含在appTests
目標中,因為app
appTests
鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.