I was wondering if you can write inline assembly in Swift.
我想知道你是否可以在Swift中编写内联汇编。
I know that in Objective-C you could use something like this:
我知道在Objective-C中你可以使用这样的东西:
inline void assemblyFunc() {
__asm__(/*Assembly*/);
}
But in Swift it seems that you can't use __asm__(/*Assembly*/)
.
但是在Swift中似乎你不能使用__asm __(/ * Assembly * /)。
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.
有没有人知道如何使用__asm __(),如果可能的话。我还没有找到任何关于它的信息,所以我认为这是一个很好的问题。
2 个解决方案
#1
12
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.
为了扩展Robert Levy所说的内容,你可以使用Swift / Obj-C互操作功能,并编写一个执行ASM内容的Obj-C类,然后可以从Swift调用它。
It's an annoying workaround, but it should work nonetheless.
这是一个令人烦恼的解决方法,但它应该工作。
You can read more about how to do it [here]
你可以阅读更多关于如何做到这一点[这里]
#2
10
There isn't a way in Swift itself. If you need this, probably a good opportunity to take advantage of Swift-ObjC interop.
Swift本身没有办法。如果你需要这个,可能是利用Swift-ObjC互操作的好机会。
#1
12
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.
为了扩展Robert Levy所说的内容,你可以使用Swift / Obj-C互操作功能,并编写一个执行ASM内容的Obj-C类,然后可以从Swift调用它。
It's an annoying workaround, but it should work nonetheless.
这是一个令人烦恼的解决方法,但它应该工作。
You can read more about how to do it [here]
你可以阅读更多关于如何做到这一点[这里]
#2
10
There isn't a way in Swift itself. If you need this, probably a good opportunity to take advantage of Swift-ObjC interop.
Swift本身没有办法。如果你需要这个,可能是利用Swift-ObjC互操作的好机会。