从C调用Swift [英] Calling Swift from C

查看:102
本文介绍了从C调用Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过很多文章,它们解释了如何从Swift调用 C函数,但是我想探索相反的方法(如果可能),以便从C调用 Swift函数

I have seen many articles explaining how to call C functions from Swift, but I would like to explore the converse (if possible), to call Swift functions from C.

我已经看到了一些示例,这些示例说明了objC中的Swift函数,但是这些并没有使我更加接近我的目标.是否支持此任务?

I have seen examples illustrating Swift functions in objC, but these do not get me any closer to my goal. Is this task even supported?

推荐答案

从C代码调用Swift代码的唯一受支持的方法是在两者之间使用Objective-C.

The only supported way to call Swift code from C code is to use Objective-C between the two.

这并不是说这是完全不可能的,但是有人将不得不想出一个NSInvocation类的实用程序,并为没有确切C表示形式的对象提供包装器.

That's not to say that it's entirely impossible, but someone would have to come up with a NSInvocation-like utility and wrappers for objects that don't have an exact C representation.

这篇关于从C调用Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆