swift-cocoaframework中module.map配

2018-07-04  本文已影响176人  ksnowlv

在swift framework中,如果要引用c库,可采用配置module.map.

那如何配置呢?我们以CommonCrypto为例。

一.工程目录下创建CommonCrypto文件夹,并分别创建module.mapYKBaseFramework-C.h
module CommonCrypto [system] {
    //header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/CommonCrypto/CommonCrypto.h"

    //header "/usr/include/CommonCrypto/CommonCrypto.h"
    header "YKBaseFramework-C.h"
    link "CommonCrypto"
    export *
}

目录如下图,注意目录的相对路径


屏幕快照 2018-07-04 下午2.23.10.png
//  YKBaseFramework-C.h
//  YKBaseFramework
//
//  Created by ksnowlv on 2018/7/4.
//  Copyright © 2018年 ksnowlv. All rights reserved.
//

#ifndef YKBaseFramework_C_h
#define YKBaseFramework_C_h

#include <CommonCrypto/CommonCrypto.h>

#endif /* YKBaseFramework_C_h */
二.设置module.map编译器目录引用路径。

在Build Settings, Swift Compiler – Search Paths 下 Import Paths中设置目录路径即可。

注意与上图目录实际位置一致!!!

屏幕快照 2018-07-04 下午2.25.53.png
三.引用CommonCrypto

注意clean,在swift code直接引入CommonCrypto即可。

import Foundation
import Security
import CommonCrypto

4.其它

上一篇 下一篇

猜你喜欢

热点阅读