[英]Swift classes marked with @objc not being added to “-Swift.h” header in mixed Objective-C/Swift framework
I am attempting to convert an old statically linked library to a framework. 我正在尝试将旧的静态链接库转换为框架。 With mixed swift and objective c in the static library, all headers are generated correctly.
在静态库中混合使用swift和目标c时,可以正确生成所有标头。 However, switching to a framework target and adding swift files, marked with the @objc header, the class is not added to the -Swift.h header.
但是,切换到框架目标并添加带有@objc标头的swift文件时,该类不会添加到-Swift.h标头中。 I can import the header, but swift classes are not found.
我可以导入标头,但找不到快速类。 This is in Xcode 10.2 and attempted using both Swift 4.2 and 5.
这在Xcode 10.2中,并且尝试同时使用Swift 4.2和5。
Are there any particular settings in XCode that will affect the generation of the *-Swift.h header in a mixed Objective C/Swift framework target? XCode中是否有任何特定设置会影响混合的Objective C / Swift框架目标中* -Swift.h标头的生成?
I had a similar issue. 我有一个类似的问题。 In my case it was a known issue in Xcode 10.2:
就我而言,这是Xcode 10.2中的一个已知问题:
https://developer.apple.com/documentation/xcode_release_notes/xcode_10_2_release_notes https://developer.apple.com/documentation/xcode_release_notes/xcode_10_2_release_notes
If you're building a framework containing Swift code and using lipo to create a binary that supports both device and simulator platforms, you must also combine the generated Framework-Swift.h headers for each platform to create a header that supports both device and simulator platforms.
如果您要构建一个包含Swift代码的框架,并使用lipo创建同时支持设备和模拟器平台的二进制文件,则还必须为每个平台组合生成的Framework-Swift.h标头,以创建同时支持设备和模拟器的标头平台。 (48635615) ...
(48635615)...
In my case all I had to do was to update the Carthage
to the newest version 0.33.0
就我而言,我要做的就是将
Carthage
更新为最新版本0.33.0
The problem appears to be a combination of Apple's new build system, the expectations they set when compiling and the number of inter-dependencies in the project setup. 问题似乎是苹果新的构建系统,他们在编译时设定的期望以及项目设置中相互依存关系的数量的结合。
The new build system runs the Swift compilations in parallel. 新的构建系统并行运行Swift编译。 When having multiple library/framework dependencies that are mixed Objective C and Swift, the compiler appears to not generate the -Swift.h files on time.
当具有多个目标库和Swift混合的库/框架依赖项时,编译器似乎未按时生成-Swift.h文件。 In static libraries, the -Swift.h files appear to be generated at the end of the Swift Compilation process, meaning they are not generated quickly enough to be used by the Objective C files when the Objective C compilation occurs.
在静态库中,-Swift.h文件似乎是在Swift编译过程结束时生成的,这意味着在进行Objective C编译时,生成它们的速度不够快,无法由Objective C文件使用。 When generating a framework, it appears that the Compiler generates the header at the beginning of the compilation process and the Swift files are not fully compiled and the -Swift.h file does not generate appropriately with the Objective C class interfaces and protocols.
生成框架时,似乎编译器会在编译过程开始时生成标头,并且Swift文件未完全编译,并且-Swift.h文件无法使用Objective C类接口和协议正确生成。
What this means ends up meaning is that we can not rely on the "target dependencies" to build the dependent projects correctly. 这意味着最终的意思是,我们不能依靠“目标依赖项”来正确构建依赖项。
So how can we build our .framework of mixed Objective C and -Swift.h without a ton of manual scripting. 因此,如何在没有大量手动脚本的情况下构建混合了Objective C和-Swift.h的.framework。
Here are the tricks I discovered that will work. 这是我发现将起作用的技巧。
Below is an example script for copying the *-Swift.h file post build. 以下是用于复制* -Swift.h文件发布版本的示例脚本。
header_file="${TARGET_TEMP_DIR}/../${PRODUCT_MODULE_NAME}.build/DerivedSources/${PRODUCT_MODULE_NAME}-Swift.h"
header_dir="${BUILT_PRODUCTS_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}"
mkdir -p "$DIR"
echo "copying $header_file $header_dir"
cp -f "$FILE" "$DIR"
UPDATED 更新
Marking all modules Swift compilation mode to "Whole Module" appears to have a positive affect on this issue, but I have not fully tested it. 将所有模块都标记为Swift编译模式为“ Whole Module”似乎对这个问题有积极的影响,但是我还没有对其进行全面的测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.