类在目标中被多次链接 [英] Class are being linked more than once in target

查看:151
本文介绍了类在目标中被多次链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个目标appappTests.我也有类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

的第8行

具有相同名称的

RLMObject子类不能在同一目标中包含两次.请确保葡萄酒"仅链接到您当前的目标一次.

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

在nhgrif评论后进行编辑

好吧,似乎在第7行出现了异常,这要感谢nhgrif了.

解决方案

Wine.swift仅应位于app中,而不能位于appTests中.在两个结果中都包含它会导致appTests具有两个名为Wine的类(app.WineappTests.Wine),而Realm不支持该类.只要Winepublic(或在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆