I have two targets in my Swift project:
There is a function in app target that is not used anywhere in the app, but it is used in tests. As a result I get build error: Undefined symbols for architecture arm64:
. It says that the function is undefined and it is referenced from tests.
It looks like compiler removes this unused function from app.
Question: How to make unused function included in the app build?
Note: I do not want to add app's source file to Compile Sources
of the test target. I prefer marking app's functions as public
and then import the app module in tests instead.
Here is how I currently make it build functions which are unused in the app. This way I can use them in tests.
class IncludeUnusedHack {
init() {
if NSDate.date().timeIntervalSinceNow > 10_000_000 {
MyClass.unusedFunctionOne()
MyClass.unusedFunctionTwo()
}
}
}
class AppDelegate: UIResponder, UIApplicationDelegate {
let unusedHack = IncludeUnusedHack()
...
}
我也遇到过这样的问题,然后我通过关闭一个选项解决了。
app(in TARGETS) > Build Settings > Linking > Dead Code Stripping
I believe this is a bug in Xcode up through 6.1 Beta 2. It looks like Xcode 6.1 Beta 3 fixes it though (released today, 9/29). From the release notes:
Testing
• Dead code stripping no longer removes public declarations from Swift application targets which are needed by unit testing. (18173029)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.