从传递浮点数数组的 C 函数调用 Objective C 函数
我正在尝试传递浮点数数组的引用。 问题是调用,因为我正在为 c 开发,但我想调用 Objective C 函数,有人可以帮助我吗?我怎样才能拨打电话? 代码在这里:
bool VideoCamera_Camera(float *buffer) {
[VideoCameraBinded VideoCamera_CameraUpdateBinded: buffer];
}
谢谢
I´m trying to pass a reference of array of floats.
The problem is the call, because I´am developing for c but I want to make a call to an Objective C Function, Could anyone help me? How can I make the call?
There you have the code:
bool VideoCamera_Camera(float *buffer) {
[VideoCameraBinded VideoCamera_CameraUpdateBinded: buffer];
}
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设 VideoCameraBinded 是一个实例,而不是一个类。如果我错了,请告诉我。
如果您在 VideoCameraBinded 的类上定义了一个方法,如下所示:
那么我不知道您的问题来自哪里。您是否遇到特定错误或其他问题?
I'm going to assume that VideoCameraBinded is an instance, and not a class. If I am mistaken, please let me know.
If you have a method defined on VideoCameraBinded's class, something like this:
then I don't know where your problem is coming from. Are you getting a specific error or some other issue?
如果您有权访问并可以更改 Objective-C 代码,请在其中添加 C API。
否则,如果你确实无法更改 Objective-C 代码,你可以直接使用 Objective-C 运行时,但这是不鼓励的:
你需要链接到 Objective-C 运行时库,通常是 libobjc:
如果 Objective-C 方法如果需要
NSArray *
而不是float *
,您可以将 Core Foundation 与CFArrayRef
结合使用。CFArrayRef
和NSArray *
可以互换,但CFArrayRef
是 C 类型,因此您可以使用它。CFNumberRef
和NSNumber *
也是如此,请参阅 Apple 的相关文档。If you have access to and can change the Objective-C code, add a C API there.
Otherwise, if you really can't change the Objective-C code you can use the Objective-C runtime directly, but this is discouraged:
You need to link to an Objective-C runtime library, usually libobjc:
If the Objective-C method expects an
NSArray *
instead of afloat *
, you can use Core Foundation withCFArrayRef
.CFArrayRef
andNSArray *
are interchangeable, butCFArrayRef
is a C type so you can use that. Same goes forCFNumberRef
andNSNumber *
, see Apple's documentation on this.VideoCamera_CameraUpdateBinded:
的参数类型是什么?如果它是 NSArray 那么你必须循环,创建一个数组并像任何其他 obj-c 方法一样发送它。您必须将浮点数存储在某种对象中(例如
NSNumber
)。否则,如果 obj-c 函数采用 float* 那么你应该可以开始了。
顺便说一句,你不应该传递一个 bufferSize 参数吗?
What is the parameter type for
VideoCamera_CameraUpdateBinded:
?If its NSArray then you have to loop, create an array and send it like any other obj-c method. You'll have to store the floats in some kind of objects (e.g.
NSNumber
).Otherwise, if the obj-c function is taking a float* then you should be good to go.
BTW, shouldn't you pass a bufferSize parameter too?