by david2ndaccount · 5y ago · 0 comments
However the intent of the Swift call described in the article is indeed that of a string literal with 2 data "parameters".
So is the correct use of NSLog in this case is this:
NSLog("%@", "Failed to get modification date at URL: \(url) - \(error)")
This should really be the behavior of NSLog in Swift, that it expands not to the variadic NSLog(format-string-parameter, objc-object-parameters..)
but to NSLog(@"%@", string-parameter)So a native Swift API would be able to distinguish and refuse to let you provide this String where a StaticString is the appropriate thing, I am not an Apple expert to say whether this would be possible / easy for the NSLog binding, if it was possible to do this it should have been done.
NSLog might be considered an exception vs other Objective-C usage of format strings - but it might also not be worth having a singular special case.
NSLog(“Failed to get modification date at URL: %@ - %@“, url.absoluteString, error.localizedDescription)