I'm trying to write an open source app to show how you can write client + server code in Swift. The source code is located here: https://github.com/haaakon/QuizWorld (QW for short)
The app is using a framework, located here: https://github.com/haaakon/QuizWorld-API (QWAPI) to access the API. I've imported the QWAAPI as a project into the QW app, it runs fine in simulator, but when running the tests, it doesn't compile because of this Error:
Undefined symbols for architecture x86_64:
"QuizWorld.QuestionViewModel.__allocating_init () -> QuizWorld.QuestionViewModel", referenced from
This is from only one line of code in the test:
let a = QuestionViewModel()
This means that the test target does not correctly get the imported module in. The imports are:
@testable import QuizWorld
@testable import QuizWorldAPI
import Prelude
import ReactiveSwift
import ReactiveExtensions
import Result
I've tried adding alot of different imports, even for the Frameworks used in the API Framework, but nothing seems to fix this. The QW-Tests target also has the correct target dependency setup. Anyone have a clue where i can go next with this? All the code is open source in the repos linked to.
So select your iOS App and then select the target you want to link with. Then go to the General tab and click (+) in Frameworks, Libraries, and Embedded Content section, then select your framework and click Add. Link the framework to the app.
To add a unit test target to an existing Xcode project, choose File > New > Target. Select your app platform (iOS, macOS, watchOS, tvOS) from the top of the New Target Assistant. Select the Unit Testing Bundle target from the list of targets.
In your test target, you have nothing set in Test Host
and Bundle loader
build settings. During linking phase it basically fails (doesn't know where from) to load the symbols. Target dependencies only says what should be built before, and "Link binary with libraries" has no effect for dynamic frameworks.
Set following build settings in your test target:
Test Host: $(BUILT_PRODUCTS_DIR)/QuizWorld.app/QuizWorld
Bundle Loader: $(TEST_HOST)
The docs for the latter:
Specifies the executable that will be loading the bundle output file being linked. Undefined symbols from the bundle are checked against the specified executable like it was one of the dynamic libraries the bundle was linked with.
I tried this on your project and it works.
UPD: In your second commit "setup for first test" you have removed these lines, so you might just reverse deletion of those individual lines.
UPD2: Regarding your general project setup. Try running your app on a real device, with this setup it won't find 3rd party frameworks included from QWAPI project, as they are not copied automatically. You will need to setup "Copy frameworks" build phase, to make sure that dynamic frameworks are copied in to the app bundle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With