Hello! I’d like to propose a new feature for Swift-DocC to add some functionality that’s currently missing: Giving documentation articles their own platform availability information, separately from the “fallback” data given for the catalog as a whole.
Currently, platform availability is set in one of two ways:
- Directly from source code, in
@available
attributes in Swift and the equivalent attributes in Objective-C, or - The “Default Availability” entry in the Info.plist for a documentation catalog, or the
--platform
flag todocc
itself, which both set platform availability for the catalog as a whole.
Critically, this means that the only kinds of documentation pages that can currently set their own platform availability are symbols, and only if their source code (and symbol graph translation) have that availability set. If you were to write a documentation article or tutorial that relied on OS APIs that were added in a certain platform version, you would have to write this in your prose, separately from the page metadata that symbols otherwise get for free.
In addition, there are extra signals that are associated with “platform versioning” that are also valuable, such as deprecation, or even currently unavailable, such as “Beta” designation.
Proposed solution
I would like to add a new metadata directive that acts as an analog of the @available
attribute in Swift, for the kinds of information that Swift-DocC currently uses and displays. It would allow you to set an article’s platform availability as if it were a symbol, and override a symbol’s availability via a documentation extension. This lets you flag some piece of content as only being valid for some platform or OS version.
The attribute operates similarly to the @available
attribute in Swift. It would be written in the page metadata and look something like this:
@Metadata {
@Available(iOS, introduced: "12.0")
@Available(macOS, introduced: "10.14")
}
@Metadata {
@Available(*, deprecated: true)
}
@Metadata {
@Available(*, isBeta: true)
}
The first argument matches the list of platforms from the Swift reference, linked above. An asterisk (*
) can be used to indicate “all platforms” for the purposes of applying deprecation or beta status.
The introduced
argument allows you to specify a version number for a specific platform. The deprecated
argument allows you to indicate that the page should be marked as “deprecated”. To write a deprecation message to display on the page, the @DeprecationSummary
directive can be used. Conversely, the isBeta
argument can be used to mark the page as “Beta”.
Open questions
- What combination of attribute arguments makes sense to support? The
@available
attribute in Swift supports much more metadata than Swift-DocC currently renders. - Should we extend this attribute to include information without an analog in source, like the package version an API was introduced in? Or even an arbitrary string? Could that information live in a separate attribute without being too confusing, or should
@Available
be designed to accept this information as well?
Let me know what you think! In combination with my other proposal for Sample Code links and page kinds, this can provide a powerful mechanism to mark what OS version(s) a sample requires. I’m excited to add this feature to Swift-DocC and make documentation even more powerful.