Embedded Content Contains Swift Code

So today while writing some UnitTests I came accross an interesting error: The only error message that appeared in XCode's debug window was the following:

*** Test session exited(1) without checking in. If you believe this error represents a bug, please attach the log file at /var/folders/23/36qtwy8n2kd_y0jt77wqjdy00000gn/T/com.apple.dt.XCTest-status/Session-2015-09-07_13:01:12-Hg8qMm.log

After a debug session I discovered, that the usual suspect is the problem here: The Build Option "Embedded Content Contains Swift Code".

The cause was that one of the lower tier frameworks that contained Swift code had this flag not enabled and was linked in a higher tier framework's test target.

So why did I discover this bug only when I wrote tests and not earlier? The answer ist that when you build the application that uses multiple frameworks of different tiers, the @rpath/libswiftCore.dylib was already linked in the whole bundle.

Full error log:

2015-09-07 13:01:24.775 xctest[28784:1480273] The test bundle at /Volumes/RamDisk/DerivedData/Frameworks-dmkijosdknpizdehyskyleppvfvd/Build/Products/Debug-iphonesimulator/XXXTests.xctest could not be loaded because an unanticipated error occurred.
2015-09-07 13:01:24.776 xctest[28784:1480273] Detailed error information: Error Domain=NSCocoaErrorDomain Code=3587 "The bundle “XXXTests” couldn’t be loaded because it is damaged or missing necessary resources." (dlopen_preflight(/Volumes/RamDisk/DerivedData/Frameworks-dmkijosdknpizdehyskyleppvfvd/Build/Products/Debug-iphonesimulator/XXXTests.xctest/XXXTests): Library not loaded: @rpath/libswiftCore.dylib
Referenced from: /Volumes/RamDisk/DerivedData/Frameworks-dmkijosdknpizdehyskyleppvfvd/Build/Products/Debug-iphonesimulator/OTHER-XXX.framework/OTHER-XXX
Reason: image not found) UserInfo=0x7ae48e30 {NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSFilePath=/Volumes/RamDisk/DerivedData/Frameworks-dmkijosdknpizdehyskyleppvfvd/Build/Products/Debug-iphonesimulator/XXXTests.xctest/XXXTests, NSLocalizedFailureReason=The bundle is damaged or missing necessary resources., NSLocalizedDescription=The bundle “XXXTests” couldn’t be loaded because it is damaged or missing necessary resources., NSDebugDescription=dlopen_preflight(/Volumes/RamDisk/DerivedData/Frameworks-dmkijosdknpizdehyskyleppvfvd/Build/Products/Debug-iphonesimulator/XXXTests.xctest/XXXTests): Library not loaded: @rpath/libswiftCore.dylib
Referenced from: /Volumes/RamDisk/DerivedData/Frameworks-dmkijosdknpizdehyskyleppvfvd/Build/Products/Debug-iphonesimulator/OTHER-XXX.framework/OTHER-XXX
Reason: image not found, NSBundlePath=/Volumes/RamDisk/DerivedData/Frameworks-dmkijosdknpizdehyskyleppvfvd/Build/Products/Debug-iphonesimulator/XXXTests.xctest}


*** Test session exited(1) without checking in. If you believe this error represents a bug, please attach the log file at /var/folders/23/36qtwy8n2kd_y0jt77wqjdy00000gn/T/com.apple.dt.XCTest-status/Session-2015-09-07_13:01:12-Hg8qMm.log