没有这样的模块Common Crypto

时间:2017-10-23 16:30:46

标签: ios swift bridging-header commoncrypto objc-bridging-header

我正在使用swift 3.2。我做了一个桥接头文件,其中包含以下内容:

#import <CommonCrypto/CommonCrypto.h>

在我的项目构建设置中,我指向我的桥接头文件,但我仍在我的类中使用import CommonCrypto获取错误'No such module CommonCrypto'

更新: 头文件:

#ifndef ProjectName_Bridging_Header_h
#define ProjectName_Bridging_Header_h

#import <CommonCrypto/CommonCrypto.h>

#endif

1 个答案:

答案 0 :(得分:1)

我找到了解决办法,让Xcode能够通过Miift Isaev所述的here通过Swift模块找到CommonCrypto

我在我的项目中使用了这种方法(Xcode 9.3,Swift 4)。我总结了以下步骤。

  1. 在项目的根目录中创建一个新目录CommonCrypto(或者我在AppDelegate.swift文件的同一级别创建它)
  2. 在该目录内创建文件名module.map(在Xcode外部完成),内容如下

    module CommonCrypto [system] {
       header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h"
       export *
    }
    

    如果您在其他位置安装Xcode,您可以自己手动查找此类.app的位置,然后将其附加到/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h,或者您可以执行xcode-select -p以获取Xcode的路径,然后将其附加到/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h

  3. 转到Xcode中的Build Settings,然后搜索swift compiler - search paths

  4. $(PROJECT_DIR)/<project name>/CommonCrypto中输入Import Paths,其中<project name>是您的项目名称。
  5. 现在您将能够构建项目,Xcode将找到这样的模块。
  6. 注意:无需通过CommonCrypto将承载module.map文件的Add Files to ...目录添加到Xcode中。它只用于编译步骤,因此没有问题。

相关问题