github地址:https://github.com/LINGLemon/LXFSwiftApp
1、创建c文件:testC.h
和testC.c
testC.h
内容如下:
#ifndef testC_h
#define testC_h
#include <stdio.h>
void showValue(int *value);
#endif /* testC_h */
testC.c
内容如下
#include "testC.h"
void showValue(int *value) {
printf("old value = %d\n",*value);
*value = *value + 1;
printf("new value = %d\n",*value);
}
2、在桥接文件中,加入testC.h
引用:#include "testC.h"
3、swift中调用
var value: Int32 = 0
showValue(&value)
终端输出:
old value = 0
new value = 1