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
Copy the code

Solution [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:

  1. Project MyExistingApp -> + Add Target -> iOS -> Other -> Cocoa Unit Testing Bundle
  2. Name the new target something like “Unit Tests” or “MyAppTests”
  3. Select your new “Unit Tests” target and click the Build Phases tab, expand Target Dependencies and add MyExistingApp as as a Target Dependency
  4. Click the Build Settings tab and set the Bundle Loader setting to
$(BUILT_PRODUCTS_DIR)/MyExistingApp.app/MyExistingApp
Copy the code
  1. Set the Test Host build setting to
$(BUNDLE_LOADER)
Copy the code
  1. Go back to your app target (not the test target), set the Symbols Hidden by Default build setting to
NO
Copy the code

After testing the following Settings can also compile successfully

Bundle Loader = $(TEST_HOST)
Test Host = $(BUILT_PRODUCTS_DIR)/MyExistingApp.app/MyExistingApp
Copy the code