[swift-users] Passing variadic C args through?
Rick Mann
rmann at latencyzero.com
Tue Nov 14 19:19:41 CST 2017
I've had a long-working `debugLog()` method that looks like this:
```
func
debugLog<T>(_ inMsg: T, file inFile : String = #file, line inLine : Int = #line)
{
let file = (inFile as NSString).lastPathComponent
let s = "\(file):\(inLine) \(inMsg)"
print(s)
}
```
I wanted to add a version that works like `String(format:)`:
```
func
debugLog(format inFormat: String, file inFile : String = #file, line inLine : Int = #line, _ inArgs: CVarArg...)
{
let s = String(format: inFormat, inArgs)
debugLog(s, file: inFile, line: inLine)
}
```
While this compiles and executes, all of the values are zero for this example:
```
let xc = CGFloat(1.0)
let yc = CGFloat(0.0)
let len = CGFloat(282.1364917907643)
debugLog(format: "Pixel %f, %f length too far %f", xc, yc, len)
```
Output:
```
FisheyeImageRenderer.swift:108 Pixel 0.000000, 0.000000 length too far 0.000000
```
Something is being misinterpreted in the passing of `inArgs: CVarArg...`
TIA,
--
Rick Mann
rmann at latencyzero.com
More information about the swift-users
mailing list