So only
_FormatSpecifiable
can supply aspecifier
and_FormatSpecifiable
is not public, these_FormatSpecifiable
must be fixed, so regular user cannot add their own. Aren't they just whateverNSLocalizedString
allow?
Sorry to revive this old post but, in case anyone else ends up here trying to solve the same kind of problem, I'd like to explain something.
_FormatSpecifiable
is a public protocol. It is however undocumented. (It's impossible to have a non-public protocol in a public API.)
The actual public protocol is:
public protocol _FormatSpecifiable : Swift.Equatable {
associatedtype _Arg : Swift.CVarArg
var _arg: Self._Arg { get }
var _specifier: Swift.String { get }
}
It's found in SwiftUI's swiftinterface file:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/SwiftUI.framework/Modules/SwiftUI.swiftmodule/arm64e-apple-ios.swiftinterface
You can see the public interface for how they have implemented it for stdlib types:
extension Int : SwiftUI._FormatSpecifiable {
public var _arg: Swift.Int64 {
get
}
public var _specifier: Swift.String {
get
}
public typealias _Arg = Swift.Int64
}
Knowing this you could go into a playground and simply:
print(42._arg) // prints 42
print(42._specifier) // prints %lld
print(CGFloat(42)._arg) // prints 42.0
print(CGFloat(42)._specifier) // prints %lf
Etc.
However given that there is no documentation about this and its types have been marked with _
meaning, "for Apple's use only", I would recommend to not conform to this, or if you need to use it, then file developer support ticket and/or a feedback assistant issue to and see if we can ask them to make this public and document it.