|
| 1 | +# Generating Documentation for Extended Types |
| 2 | + |
| 3 | +Generate documentation for the extensions you make to types from other modules. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +By default, the Swift-DocC plugin ignores extensions you make to types that are not from the module you're generating documentation for. |
| 8 | + |
| 9 | +To include documentation for extended types, add the `--include-extended-types` flag to your invocations: |
| 10 | + |
| 11 | + $ swift package generate-documentation --include-extended-types |
| 12 | + |
| 13 | +> Note: Extension support is available when using Swift 5.8 or later and the Swift-DocC plugin 1.2 or later. |
| 14 | +
|
| 15 | +## Understanding What is Included by Default |
| 16 | + |
| 17 | +Not everything that is declared in an extension is hidden behind the `--include-extended-types` flag. If the extension is declared in the same target as the type it is extending, the extension's contents will be included in the documentation by default. |
| 18 | + |
| 19 | +```swift |
| 20 | +public struct Sloth { } |
| 21 | + |
| 22 | +extension Sloth { |
| 23 | + // This function is included in the |
| 24 | + // documentation by default. |
| 25 | + public func wake() { /* ... */ } |
| 26 | +} |
| 27 | + |
| 28 | +// `Collection` is from the standard library, |
| 29 | +// not the `SlothCreator` library, so this is |
| 30 | +// what we call an "extended type". |
| 31 | +extension Collection where Element == Sloth { |
| 32 | + // This property is not included in |
| 33 | + // the documentation by default. |
| 34 | + public func wake() { |
| 35 | + for sloth in self { |
| 36 | + sloth.wake() |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +## Finding Extended Types in your Documentation |
| 43 | + |
| 44 | +Extended Types are part of the documentation archive of the target that declares the extensions. |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +Within that documentation archive, Extended Types are grouped by the Extended Module they belong to. You can find the latter on your documentation's landing page in a section called "Extended Modules". In our example from above, we have one Extended Module called "Swift" - the name of the standard library. This page can be referenced like this: ` ``SlothCreator/Swift`` `. |
| 49 | + |
| 50 | +The Extended Type ` ``SlothCreator/Swift/Collection`` ` is a child of the Extended Module and is listed under "Extended Protocols" on the ` ``SlothCreator/Swift`` ` page. |
| 51 | + |
| 52 | +> Note: The references above use the full path, including the name of the catalog's target, `SlothCreator`. This should help to understand the symbol's exact location, but usually isn't necessary. |
| 53 | +
|
| 54 | +<!-- Copyright (c) 2023 Apple Inc and the Swift Project authors. All Rights Reserved. --> |
0 commit comments