Incorrect argument label in call String format

x and y are Int values
String(format:"start: x: %d, y: %d end x: %d, y: %d", start.x, start.y, end.x, end.y)

error: incorrect argument label in call (have 'format:::::', expected 'stringInterpolation:::::')

you need to import Foundation

Also, I'd suggest that you consider using string interpolation

// like this
"start: x: \(start.x), y: \(start.y), end x: \(end.x), y: \(end.y)"
// or better
"start \(start), end \(end)"

The first one will definitely work, since it's dealing with only Int.
The second should work with most types right off the bat, but may require start and end to conform to CustomStringConvertible, which does give you a lot more flexibilitty.

1 Like

Great I decided to use the first option, I mean with out format

Do note as well that most third-party structs will support second format right off the bat, and even for simple struct it'd work mostly as you'd expect. So you could reduce the amount of typing when printing debugging stuffs.

import Foundation

struct Test {
  var x, y: Int

print(CGPoint(x: 1, y: 10)) // (1.0, 10.0)
print(NSPoint(x: 1, y: 10)) // (1.0, 10.0)
print(AnchorPoint(x: 1, y: 10)) // AnchorPoint(x: 1, y: 10)
print(Test(x: 1, y: 10)) // Test(x: 1, y: 10)
Terms of Service

Privacy Policy

Cookie Policy