After deprecating some functionality, I have a bunch of classes and functions with the @available attribute like this:
@available(*, deprecated, message: "Deprecated. Some explanation comes here. See Help Page Name for more information.")
I don't like that I have duplicate text spread in multiple places. I would rather have the text defined somewhere and used as a parameter. Naive implementation, which doesn't work, would look like this:
struct AvailabilityConstants {
static let explanationA = "Some explanation comes here. See Help Page Name for more information."
static let explanationB = "Another explanation comes here. See Another Help Page Name for more information."
}
and then use them as
@available(*, deprecated, message: AvailabilityConstants.explanationA)
etc. But as I said that doesn't work, gives an error:
Expected string literal in 'available' attribute
Indeed: strange to expect compile-time attribute to consume its compilation product.
Are there any other options? Is it even possible to parameterize attributes?