Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class are being linked more than once in target

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.

like image 664
Błażej Avatar asked Jun 23 '15 12:06

Błażej


People also ask

What is difference between target and scheme in Xcode?

A Target specifies a product to build and contains the instructions for building the product from a set of files in a project or workspace. An Xcode scheme defines a collection of targets to build, a configuration to use when building, and a collection of tests to execute.

Where is target membership in Xcode?

You can access Target Membership by selecting file and opening the right menu in Xcode (the menu is called Inspectors ). Then, in File Inspector at the bottom of the menu, find Target Membership . It's very important to check all files in your project because without this you won't be able to build a new app target.

What is an IOS target?

A target defines a single product; it organizes the inputs into the build system—the source files and instructions for processing those source files—required to build that product. Projects can contain one or more targets, each of which produces one product.

What are targets in Swift?

Overview. Each target contains a set of source files that Swift Package Manager compiles into a module or test suite. You can vend targets to other packages by defining products that include the targets. A target may depend on other targets within the same package and on products vended by the package's dependencies.

How to target elements with different classes and IDs?

Select the element which has an ID of header and also a class name of callout. The big point here is that you can target elements that have combinations of classes and IDs by stringing those selectors together without spaces.

Is it okay to have two job profiles on LinkedIn?

Thank you for sharing that you are in job-search mode and targeting two various job types. This is a viable approach in today’s competitive environment. Plus, it’s great to have two areas of passion. In terms of LinkedIn, I do not recommend two different profiles.

What is the advantage of using multiple classes in CSS?

The second targets the same element, but overrides the color, instead of having to use: or perhaps prefacing the selector with something even more specific. More useful is multiple classes and using them in the “object oriented” css style that is all the rage lately.

Will I know if the same person views my LinkedIn multiple times?

If the same person views my LinkedIn several times in a day, will I know? Yes, if it’s not an immediate reload of a page. I’ve had many people view my profile twice in the same day and it shows up as two separate notifications. How many profile views does the average LinkedIn user get in a day? I write 1-2 posts per week. I engage people often.


1 Answers

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.

like image 124
Thomas Goyne Avatar answered Oct 18 '22 02:10

Thomas Goyne