Undefined symbols for architecture x86_64:
"direct field offset for appTarget.class.titles : [Swift.String]", referenced from:
implicit closure #1 () throws -> Swift.Bool in testTarget.class.testExample() -> () in RiverAppInstrumentationTests.o
"type metadata accessor for appTarget.class", referenced from:
testTarget.class.testExample() -> () in AppInstrumentationTests.o
ld: symbol(s) not found for architecture x86_64
解决方法【Adding Unit Tests to an existing iOS project with Xcode 4】:
If you add a unit test target to an existing iOS project, there are some manual steps required to set up the target correctly. Following these steps will get you up and running quickly:
- Project MyExistingApp -> + Add Target -> iOS -> Other -> Cocoa Unit Testing Bundle
- Name the new target something like “Unit Tests” or “MyAppTests”
- Select your new “Unit Tests” target and click the Build Phases tab, expand Target Dependencies and add MyExistingApp as as a Target Dependency
- Click the Build Settings tab and set the Bundle Loader setting to
$(BUILT_PRODUCTS_DIR)/MyExistingApp.app/MyExistingApp
- Set the Test Host build setting to
$(BUNDLE_LOADER)
- Go back to your app target (not the test target), set the Symbols Hidden by Default build setting to
NO
经过测试设置如下也可以编译成功
Bundle Loader = $(TEST_HOST)
Test Host = $(BUILT_PRODUCTS_DIR)/MyExistingApp.app/MyExistingApp