在Objective C中定义斯威夫特通话variadics C函数 [英] Swift call variadics C function defined in Objective C

查看:148
本文介绍了在Objective C中定义斯威夫特通话variadics C函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总结这个问题的步骤,我已在目标C定义的C函数:

I have summarized the steps of the problem, I have a C function defined in Objective C:

ObjC.h

#import <Foundation/Foundation.h>

void cuslog(NSString *format, ...);

@interface ObjC : NSObject

@end

ObjC.m

ObjC.m

#import "ObjC.h"

@implementation ObjC

@end

void cuslog(NSString *format, ...)
{
     // Implementation
}

我接触它桥接-Header.h:

I exposed it in Bridging-Header.h:

#import "ObjC.h"

// Also tried to put this line in bridging header
void cuslog(NSString *format, ...);

在我迅速的意图这样调用该函数:

In swift I intent to call the function like this:

cuslog("Some log")

得到的错误说:

"Use of unresolved identifier cuslog"

什么是调用快捷功能的正确方法是什么?

What is the correct way to call the function in swift?

推荐答案

据雨燕的开发者, ç参数可变型函数不能与斯威夫特variadics 兼容,所以你将不能够直接调用你的函数。

According to the Swift devs, C variadic functions are not compatible with Swift variadics, so you won't be able to call your function directly.

在这个时候,唯一的解决方法是编写C或对象 - 一个非可变参数的包装,并调用从斯威夫特。

The only workaround at this time is to write a non-variadic wrapper in C or Obj-C, and call that from Swift.

这篇关于在Objective C中定义斯威夫特通话variadics C函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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