本文介绍了如何在Swift中使用CVaListPointer参数调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我应该如何调用以下方法?该方法属于打印日志的类.
How should I invoke the following method? The method belongs to a class that prints logs.
func log(format: String!, withParameters valist: CVaListPointer)
我要实现的目标在Objective-C中如下所示:
What I want to achieve, would look like this in Objective-C:
NSLog(@"Message %@ - %@", param1, param2);
有什么想法吗?
推荐答案
CVaListPointer
是C va_list
类型的Swift等效项可以使用withVaList()
从[CVarArgType]
数组创建.
CVaListPointer
is the Swift equivalent of the C va_list
typeand can be created from an [CVarArgType]
array using withVaList()
.
示例:
func log(format: String!, withParameters valist: CVaListPointer) {
NSLogv(format, valist)
}
let args: [CVarArgType] = [ "foo", 12, 34.56 ]
withVaList(args) { log("%@ %ld %f", withParameters: $0) }
输出:
2016-04-27 21:02:54.364 prog[6125:2476685] foo 12 34.560000
对于 Swift 3,将CVarArgType
替换为CVarArg
.
这篇关于如何在Swift中使用CVaListPointer参数调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!