简体   繁体   English

从 C 调用 Swift

[英]Calling Swift from C

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 .我看过很多文章解释如何从 Swift调用C 函数,但我想探索相反的(如果可能),从 C调用Swift 函数

I have seen examples illustrating Swift functions in objC, but these do not get me any closer to my goal.我看过在 objC 中说明 Swift 函数的例子,但这些并没有让我更接近我的目标。 Is this task even supported?甚至支持这项任务吗?

The only supported way to call Swift code from C code is to use Objective-C between the two.从 C 代码调用 Swift 代码的唯一支持的方法是在两者之间使用 Objective-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 表示的对象想出一个类似NSInvocation的实用程序和包装器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM