我该如何调用以下方法?该方法属于打印日志的类.
func log(format: String!,withParameters valist: CVaListPointer)
我想要实现的目标在Objective-C中看起来像这样:
NSLog(@"Message %@ - %@",param1,param2);
有任何想法吗?
CVaListPointer是C va_list类型的Swift等价物
并且可以使用withVaList()从[CVarArgType]数组创建.
并且可以使用withVaList()从[CVarArgType]数组创建.
例:
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,用CVarArg替换CVarArgType.