New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-957] make String implement CVarArg protocol to support formats with "%@" on Linux #4368
Comments
@gparker42, @gribozavr, was there a reason we didn't do this? Was it just to avoid confusion with %s? vadim (JIRA User), you can work around this by explicitly coercing to NSString or AnyObject using |
We can't make AnyObject conform to CVarArg. |
Ah, right, of course. But that doesn't say why we wouldn't do it for String, and I think we do (or could) do it for NSObject, at least. |
Comment by Ian Partridge (JIRA)
doesn't compile on Linux, because NSObject only conforms to CVarArg on Darwin. Is fixing that a better way to go? |
Comment by Jason Ji (JIRA) Hello, just wondering if there was any progress on this? I also ran into an issue today where a call to |
Wanted to bump this, as I've run into it too. |
It'd be nice if all the bridged types conformed to CVarArg even on Darwin to avoid the |
Comment by Matthew Burke (JIRA) One more bump^Wdata point. Just ran into this as well. |
Comment by Joseph Lawson (JIRA) A patch can be found here in the mean time: IBM-Swift-Sunset/GRMustache.swift@56ecaf2 We ended up munging the data into the type desired with return String(format: NSLocalizedString("Configuration Error: %1$@", comment: "The error message displayed for configuration errors. (1: configuration error details)"), details.localized() as! CVarArg) |
Comment by Brian Gontowski (JIRA) I created PR #2821 and PR #32311 to implement the There is some discussion in the Swift forums about this. |
Comment by Brian Gontowski (JIRA) The pull requests have been merged. |
Additional Detail from JIRA
md5: 71333aaf50f2a65e850f26689b127b98
Issue Description:
make String implement CVarArg to support formats with "%@" for strings, e.g. with the following method:
https://github.com/apple/swift/blob/97d8f50af4978e54289377a0bd205e71a34529a2/stdlib/public/SDK/Foundation/NSStringAPI.swift
/// Returns a string created by using a given format string as a
/// template into which the remaining argument values are substituted
/// according to the user's default locale.
@warn_unused_result
public static func localizedStringWithFormat(
format: String, _ arguments: CVarArg...
)
A format example: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Strings/Articles/FormatStrings.html
Format specifiers:
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html
The text was updated successfully, but these errors were encountered: