How is CommonCrypto used in SWIFT3?

二次信任 提交于 2019-12-10 14:54:32

问题


The guidance is to to use #import "CommonCrypto/CommonCrypto.h" in the bridging header. This is from the question at: SHA256 in swift.
However, when I use the answers given by Andi and Graham Xcode still complains about "use of unresolved identifier CC_SHA256_DIGEST_LENGTH..."

I am thinking I've made one of two mistakes: Either (a) I am missing something in not having wired up the header and import correctly. i.e. I did not setup the bridging header correctly. I'd love clear steps on how to include the library and create the bridging header correctly. Or (b)The library is not included by default and I actually need to download it and store locally before I can use it. I'd love instructions on that.

Thanks.


回答1:


Good news!: Swift 4(Xcode 10) has made CommonCrypto to be available for import by default!

This may not be helpful for you at Swift 3 but still, it's just FYI




回答2:


better way in 8 steps

1) -------------------------------------------

go to xcode file inspector and select your project file and add a new target.

2) -------------------------------------------

select an aggregate from cross-platform section.

3) -------------------------------------------

after you name it appropriately, select it from targets and go to build phases section.

4) -------------------------------------------

there select the plus button and create new run script phase with following code. it will generate appropriate module for each platform just before building and you will be able to import CommonCrypto even for simulator.

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

5) -------------------------------------------

after this step go to your project target and actually link this aggregate to your build process

6) -------------------------------------------

select the aggregate

7) -------------------------------------------

now still in the project target go to build settings and find "header search paths" and insert this path to be traversed for the newly generated module

${SRCROOT}/Frameworks/CommonCrypto

8) -------------------------------------------

now all you need to do is just

import CommonCrypto

somewhere and start using it.

hope it helps



来源:https://stackoverflow.com/questions/45260005/how-is-commoncrypto-used-in-swift3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!