简体   繁体   English

在 objc 项目 xcode 11.3.1 中导入 swift 框架?

[英]import swift framework in objc project xcode 11.3.1?

I have question about framework.我对框架有疑问。
When I import my customized swift framework in Objc project, I cant init class object and find customized delegate.当我在 Objc 项目中导入自定义的 swift 框架时,我无法初始化 class object 并找到自定义委托。
And I also have script to combined different framework like this:而且我也有脚本来组合不同的框架,如下所示:
Is my script problem?我的脚本有问题吗?
Or project setting problem?还是项目设置问题?

Xcode 11.3.1 Xcode 11.3.1
swift 5 swift 5

#!/bin/sh
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
xcodebuild -target "XXXSDK" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos  BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "XXXSDK" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
# Step 2. Copy the framework structure (from iphoneos build) to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/XXXSDK.framework" "${UNIVERSAL_OUTPUTFOLDER}/"
# Step 3. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
SIMULATOR_SWIFT_MODULES_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/XXXSDK.framework/Modules/XXXSDK.swiftmodule/."
if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then
cp -R "${SIMULATOR_SWIFT_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/XXXSDK.framework/Modules/XXXSDK.swiftmodule"
fi
# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/XXXSDK.framework/XXXSDK" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/XXXSDK.framework/XXXSDK" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/XXXSDK.framework/XXXSDK"
# Step 5. Convenience step to copy the framework to the project's directory
cp -R "${UNIVERSAL_OUTPUTFOLDER}/XXXSDK.framework" "${PROJECT_DIR}"
cp -R "${UNIVERSAL_OUTPUTFOLDER}/XXXSDK.framework" "${PROJECT_DIR}/../../XXXSDKDemo"
cp -R "${UNIVERSAL_OUTPUTFOLDER}/XXXSDK.framework" "${PROJECT_DIR}/../../XXXSDKObjcDemo"
# Step 6. Convenience step to open the project's directory in Finder
open "${PROJECT_DIR}"

图片

If you build your framework with xcframeworks, all this configuration mess will be a lot easier.如果您使用 xcframeworks 构建您的框架,那么所有这些配置混乱都会容易得多。 If you can, give it a try.如果可以,请尝试一下。 Look at https://github.com/bielikb/xcframeworkshttps://github.com/bielikb/xcframeworks

There should not be any problem to consume swift framework in objective c, check if the framework has the correct .h file in it.在目标c中使用swift框架应该没有问题,检查框架中是否有正确的.h文件。

If you want to combine multiple framework in one the you can use lipo command from terminal.如果您想将多个框架合二为一,您可以从终端使用lipo命令。 Please do check the combined framework after lipo and see if there is the header file.请检查 lipo 之后的组合框架,看看是否有 header 文件。

Also try to use the frameworks individually before lipo.也尝试在 lipo 之前单独使用框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM