I would like to be able to use NSLog
with Swift structs. Can I? What I'm doing right now is:
extension CGRect {
var description:String {
return "\(self.left),\(self.top)_|\(self.width),\(self.height)"
}
}
NSLog("rect for something %@", self.someView.frame.description)
I had hoped that simply adding the description
var to CGRect
would be enough and I wouldn't need to explicitly add the .description
in the NSLog()
call. But when I try that I get
Argument type 'CGRect' does not conform to expected type 'CVarArgType'
It seems that arrays of structs have similar issues (because arrays are structs too?)
CGRect
adopt theCVarArgType
protocol then.CVarArgType
protocol, but it's pretty short on details what one does to make a type adopt it. It does say that many value types adopt it, so I have to believe thatCGRect
could be added to that list.