类在目标中被多次链接 [英] Class are being linked more than once in target
问题描述
我有两个目标app
和appTests
.我也有类Wine
和框架Realm
和'RealmSwift',它们链接到这两个目标.当我在traget app
中使用类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
具有相同名称的RLMObject子类不能在同一目标中包含两次.请确保葡萄酒"仅链接到您当前的目标一次.
我已经清除了DerivedData和项目.你能建议我应该去哪里看看吗?
在nhgrif评论后进行编辑
好吧,似乎在第7行出现了异常,这要感谢nhgrif了.
Wine.swift
仅应位于app
中,而不能位于appTests
中.在两个结果中都包含它会导致appTests
具有两个名为Wine
的类(app.Wine
和appTests.Wine
),而Realm不支持该类.只要Wine
是public
(或在Swift 2.0中是@Testable
),您就可以从appTests
访问它,而不必将其包含在appTests
目标中,因为appTests
链接到app
.>
I have two targets app
and appTests
. Also I have class Wine
and framework Realm
and 'RealmSwift' which are linked to those two targets. There is no exception When I use class Wine
in traget app
.
But when I want to run test like
appTests.swift (22 lines)
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 lines)
import UIKit
import RealmSwift
class Wine: Object {
dynamic var desc: String = ""
dynamic var photo: String = ""
dynamic var raiting: Double = 0
}
Then an exception appear at line 8 in appTests.swift
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.
I already did clear DerivedData and project. Could You suggest where I should look?
EDIT after nhgrif comment
Ok it appears that an exception is rising earlier, in line 7. Which is now marked in code thanks to nhgrif.
Wine.swift
should only be in app
, and not appTests
. Including it in both results in appTests
having two classes named Wine
(app.Wine
and appTests.Wine
), which is not something that Realm supports. As long as Wine
is public
(or in Swift 2.0, @Testable
), you can access it from appTests
without including it in the appTests
target because appTests
links in app
.
这篇关于类在目标中被多次链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!