是否可以在Swift中编写内联汇编? [英] Is it possible to write inline assembly in Swift?

查看:128
本文介绍了是否可以在Swift中编写内联汇编?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道您是否可以在Swift中编写内联汇编.

I was wondering if you can write inline assembly in Swift.

我知道在Objective-C中,您可以使用如下代码:

I know that in Objective-C you could use something like this:

inline void assemblyFunc() {
    __asm__(/*Assembly*/);
}

但是在Swift中,似乎不能使用__asm__(/*Assembly*/).

But in Swift it seems that you can't use __asm__(/*Assembly*/).

即使有可能,没有人知道如何使用__asm__(). 我什么都没找到,所以我认为这是一个很好的问题.

Does anyone know how to use __asm__() if its even possible. I haven't found anything about it, so I thought it would be a good question to ask.

推荐答案

要扩展Robert Levy所说的内容,您可以只使用Swift/Obj-C互操作功能,并编写一个执行ASM任务的Obj-C类. ,然后您可以从Swift调用它.

To expand on what Robert Levy said, you can just use the Swift/Obj-C interop feature, and write an Obj-C class that does the ASM stuff, which you can then call from Swift.

这是一个烦人的解决方法,但仍然可以正常工作.

It's an annoying workaround, but it should work nonetheless.

您可以在[此处]

这篇关于是否可以在Swift中编写内联汇编?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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