How to call a method with CVaListPointer parameters in Swift

How do I call the following method? The method belongs to the class that prints the logs.

func log(format: String!, withParameters valist: CVaListPointer) 

What I want to achieve will look like this: Objective-C:

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

Any ideas?

+5
source share
1 answer

CVaListPointer is the equivalent of Swift type C va_list and can be created from the [CVarArgType] array using withVaList() .

Example:

 func log(format: String!, withParameters valist: CVaListPointer) { NSLogv(format, valist) } let args: [CVarArgType] = [ "foo", 12, 34.56 ] withVaList(args) { log("%@ %ld %f", withParameters: $0) } 

Output:

  2016-04-27 21: 02: 54.364 prog [6125: 2476685] foo 12 34.560000

For Swift 3, replace CVarArgType with CVarArg .

+10
source

All Articles