目前了解到两种调用C语法方法方式:这里以系统中自带的“
/usr/include/CommonCrypto/CommonCrypto.h”为例
一: 使用桥接文件。
创建一个桥接文件xxx.h,然后在Build setting 中 “Objective-C Bridging Header” 中添加刚刚创建的xxx.h文件,例如:
然后在将需要使用的头文件名写入xxx.h文件就可以在swift中调用,此方法不近适用于C语言,同样适用于OC。例如:
二:使用swift的module。
1. 首先在工程中创建一个Group,在Group中创建一个Empty文件,命名为module.modulemap或者module.map。
2.在其中填写如下内容(注释内容不需要):
module
CommonCrypto [system] {
header
"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h"
///usr/include/CommonCrypto/CommonCrypto.h" //识别不了这个路径
//link "CommonCrypto" //不要添加这句
export *
///usr/include/CommonCrypto/CommonCrypto.h" //识别不了这个路径
//link "CommonCrypto" //不要添加这句
export *
}
注意:
网上有一部分例子中header使用的是"/usr/include/CommonCrypto/CommonCrypto.h"
但是这个路径不全,找不到相关API的。
也有的例子添加了link 这个属性,但是这个属性会造成如下错误: