ksnowlv

回顾过去,总结以往;立足现在,铭记当下;技术为主,笔记而已.

swift-cocoaframework中module.map配置

| Comments

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

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

一.工程目录下创建CommonCrypto文件夹,并分别创建module.mapYKBaseFramework-C.h
  • 1.module.map
1
2
3
4
5
6
7
8
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 *
}

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

  • 2.YKBaseFramework-C.h
1
2
3
4
5
6
7
8
9
10
11
12
13
//  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中设置目录路径即可。

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

image

三.引用CommonCrypto

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

1
2
3
import Foundation
import Security
import CommonCrypto

4.其它

  • 1.为什么不采用直接配置绝对路径引用CommonCrypto.h?

    配置为绝对路径,灵活性通用性实在太差,依赖于系统目录。

  • 2.配置CommonCrypto时,注意目录所在路径
  • 3.https://github.com/IBM-Swift/CommonCrypto

Comments

comments powered by Disqus
Included file 'custom/after_footer.html' not found in _includes directory