Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Tests linker error

I have a Swift test which uses some Objective-C code that I wrote:

class ParserServiceTest: QuickSpec {
    override func spec() {
        var x : MyClass? // this works
        x = MyClass()    // this does not
    }
}

When I try to build the project I get the error message:

Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_MyClass", referenced from:
      __TTSf4d___TTSf4g___TFC11MyProjectTests17ParserServiceTest4specfS0_FT_T_ in ParserServiceTest.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
like image 984
Bastian Avatar asked Nov 20 '25 21:11

Bastian


1 Answers

You need to include the objective-c in your test target. In your targets list, select the "...Tests" target and then the "Build Phases" pane. Look at "Compile Sources" or "Link Binary With Libraries" (depending on whether your code comes from source or a library), and make sure all the files you need are there. Most things you need to do for your executable project, you also need to do for your test project.

In the File Inspector Utility panel (right-hand panel), you can also add target membership to individual files.

like image 157
Rob Napier Avatar answered Nov 23 '25 10:11

Rob Napier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!