0

I seem to get this strange issue when testing an XCTestCase. I created a unit testing bundle, and set my main app as the "target"; now I can write tests against my Core Data NSManagedObjects just fine, but if I include anything else in my app that isn't an NSManagedObject, I get linking errors:

Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_iCloudListener", referenced from: objc-class-ref in SLTestToDoWithRepeatInterval.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

This only happens with non-NSManagedObjects. And iCloudListener is definitely in the Compiled Sources for the main app target. The problem is that though I can go and add this particular iCloudListener class into the test target -> Build Phases -> Compile Sources list, and that will make this particular linking error go away, but it introduces new ones since it starts giving linking errors about all the header files from the iCLoudListener class; and if I start adding those, they require more and more files, to the point where I have to include pretty much all of my code into the test target "Compile Sources" section.

Is there something I'm doing wrong here? Is there a setting which might be causing Xcode to ignore the non-NSManagedObject classes?

Z S
  • 7,039
  • 12
  • 53
  • 105
  • Does making the non-NSManagedObject classes members of the unit test target fix the link errors? When I get link errors like yours in my unit tests, I find making my app classes members of the unit test target eliminate the link errors. – Swift Dev Journal Jun 23 '14 at 18:38
  • It does, to an extent; but it starts giving linking errors for all the files included in the class that was originally giving the problem. By the end, I have to include virtually most of my project files into the unit test target. I have over 200 files, so it would be pretty tedious to do this, and just seems like I'm missing something. – Z S Jun 23 '14 at 18:58
  • 1
    The only other thing I can suggest is to set the Symbols Hidden By Default build setting to NO. Supposedly that will make all your app classes available to the unit test target for functional unit tests, tests that have a test host and are hosted inside your app. – Swift Dev Journal Jun 23 '14 at 19:18
  • Yes, I stumbled upon the same thing from this answer: http://stackoverflow.com/a/6624534/145552 Now my unit tests link perfectly! Thanks. – Z S Jun 23 '14 at 19:31

1 Answers1

0

It's because the project inserted the core data's xcdatamodeld file in compile sources. Select your project -> Build Phases -> Compile Sources and delete projectName.xcdatamodeld file. And also check if you have imported .m file instead of .h file, it also gives the same linker error. Check all the #import codes. And check if you have added core data frame work in library and imported core data .h file. Check for creation of NSManagedObject and import it's file. Just try it and reply me if still any error.