美文网首页
Swift Framewore 中导入CommonCrypto

Swift Framewore 中导入CommonCrypto

作者: ysCharles | 来源:发表于2017-10-25 16:11 被阅读24次

最近想要把自己积累的东西总结一下,封装到一个 framework 中去,在想要在 swift 的 framework 中使用 CommonCrypto 中的方法进行 MD5加密时遇到问题,搜索了很多文章,最终找到一个个人觉得比较好的方案,这里分享给大家。

1.新建 target 选择 Aggregate,创建一个新的 target 名字为CommonCryptoModuleMap(可以自取,我用的是这个)

WechatIMG1.jpeg

2.按照图中的步骤给这个 Aggregate 添加一个运行脚本

WechatIMG2.jpeg

脚本代码如下

# This if-statement means we'll only run the main script if the CommonCryptoModuleMap directory doesn't exist
# Because otherwise the rest of the script causes a full recompile for anything where CommonCrypto is a dependency
# Do a "Clean Build Folder" to remove this directory and trigger the rest of the script to run
if [ -d "${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap" ]; then
echo "${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap directory already exists, so skipping the rest of the script."
exit 0
fi

mkdir -p "${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap"
cat <<EOF > "${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap/module.modulemap"
module CommonCrypto [system] {
    header "${SDKROOT}/usr/include/CommonCrypto/CommonCrypto.h"
    export *
}
EOF

3.选中你的 framework,选择 build phases,在 target dependencies中添加刚才的那个 Aggregate。

WechatIMG3.jpeg

4.选在 build setting,在 header search paths 中添加${BUILT_PRODUCTS_DIR}/Aggregate 名,

WechatIMG4.jpeg
注意 不能忘记添加 $(inherited)
  1. Cmd+B 先 build 一下项目,然后就可以再你需要导入的地方使用import CommonCrypto

相关文章

网友评论

      本文标题:Swift Framewore 中导入CommonCrypto

      本文链接:https://www.haomeiwen.com/subject/bkwqpxtx.html