美文网首页
swift中如何调用c

swift中如何调用c

作者: ksnowlv | 来源:发表于2019-04-01 21:46 被阅读0次

如何在swift调用c代码呢?

swift通过工程的桥接文件,调用c的相关代码!!!

1.创建c文件:test.htest.c

test.h内容如下:

#ifndef test_h
#define test_h

#include <stdio.h>

void showValue(int *value);

#endif /* test_h */

test.c内容如下


#include "test.h"

void showValue(int *value) {
    printf("old value = %d\n",*value);
    *value = *value + 1;
    printf("new value = %d\n",*value);
}

2.在桥接文件中,加入test.h引用:#include "test.h"

3.swift中调用

   var value: Int32 = 0
   showValue(&value)
   

结果显而易见:

old value = 0
new value = 1

相关文章

网友评论

      本文标题:swift中如何调用c

      本文链接:https://www.haomeiwen.com/subject/lczbbqtx.html