Code coverage and mixed projects

Hey guys,



So I have this annoying problem, which I kind of think I know why it's happening, but I'm not sure, and of course, I don't know how to fix:


In my bridging header I have classes that import the `[name]-Swift.h` file and while everything works fine for building and testing, the moment I turn on Gather Code Coverage data, all the classes that also import `[name]-Swift.h` break and all of them report the "[name]-Swift.h file not found" error. These also appear in the logs:


Copy x86_64.swiftdoc / Copy [AppName]-Swift.h

ditto: can't get real path for source '/Users/roland/Library/Developer/Xcode/DerivedData
/Build/Intermediates/CodeCoverage/Debug/Intermediates/[AppName].build/Debug-iphonesimulator/[AppName].build/Objects-normal/x86_64/[AppName]-Swift.h / [AppName].swiftmodule'
Command /usr/bin/ditto failed with exit code 1


Generate dSYM file

error: cannot parse the debug map for "/Users/roland/Library/Developer/Xcode/DerivedData
/Build/Intermediates/CodeCoverage/Debug/Products/Debug-iphonesimulator/[AppName].app/[AppName]": No such file or directory


Copy x86_64.swiftmodule

ld: file not found: /Users/roland/Library/Developer/Xcode/DerivedData
/Build/Intermediates/CodeCoverage/Debug/Intermediates/[AppName].build/Debug-iphonesimulator/[AppName].build/Objects-normal/x86_64/[FileName].o
clang: error: linker command failed with exit code 1 (use -v to see invocation)


I read that at some point this kind of behavior was creating problems even when building, and I tried the following solutions, but none worked - importing the `[name]-Swift.h` last and creating an 'umbrella' [name]-Swift-Fixed.h` file, which only imports the real `[name]-Swift.h` file. Modules and testability are enabled, the project uses CocoaPods, but has properly set config files and `Build Active Architecture Only` is enabled.


Did anybody else encounter this? Is there any solution except rewriting the Objective-C files in Swift? 🙂



Cheers!

Replies

Have you cleaned the project after turning on code coverage to force everything to recompile with code coverage enabled?


I think I had similar errors in a past project, turning on Testability when parts of the code had already been compiled for the same architecture but without Testability enabled, and Xcode didn't realize that those files needed to be recompiled for some reason.

Yupp, Clean, Clean Build Folder, delete Derived Data, build first, then test or clean -> test directly.

Anyone? 😟

I finally found an answer and I wrote about it here http://rolandleth.com/code-coverage-issues-for-swift-projects


Short answer: variables with ternary conditioned default values. Replacing them with computed properties or lazy variables fixed it.

If you haven't filed a bug report already, please do so!