Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Swift中使用CVaListPointer参数调用方法_Swift_Logging_Swift2_Nslog - Fatal编程技术网

如何在Swift中使用CVaListPointer参数调用方法

如何在Swift中使用CVaListPointer参数调用方法,swift,logging,swift2,nslog,Swift,Logging,Swift2,Nslog,我应该如何调用以下方法?该方法属于打印日志的类 func log(format: String!, withParameters valist: CVaListPointer) 我想要实现的目标在Objective-C中是这样的: NSLog(@"Message %@ - %@", param1, param2); 有什么想法吗?CVaListPointer是Cva_列表类型的Swift等价物 可以使用withVaList()从[CVarArgType]数组创建 例如: func log(f

我应该如何调用以下方法?该方法属于打印日志的类

func log(format: String!, withParameters valist: CVaListPointer)
我想要实现的目标在Objective-C中是这样的:

NSLog(@"Message %@ - %@", param1, param2);

有什么想法吗?

CVaListPointer
是C
va_列表类型的Swift等价物
可以使用
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 2016-04-27 21:02:54.364 prog[6125:2476685]foo 12 34.560000
对于Swift 3,
CVarArg
替换
CVarArg类型

对于采用
CVarArg
而不是
CVaListPointer
的函数,您可以推荐什么?如果用
CVarArg
替换
CVarArgType
,编译器将显示类型错误,如果您尝试将
CVarArg
强制转换为
CVarArgType
,您将遇到崩溃。根据,
getVaList()
方法也返回
CVaListPointer
给定
CVarArg
@AhmedOsama的列表,
withVaList
是首选方法。