Linking DocC to package named types

May 2, 2022 · Follow on Twitter and Mastodon swiftspmdocc

In this post, let’s take a look at how to link DocC to types that have the same name as the target they belong to.

DocC icon

In DocC, targets have precedence over types, which means that if you link to a type that has the same name as the target, DocC will link to the target instead of the type.

That means that for my BottomSheet library, which has a SwiftUI view that’s also called BottomSheet, linking like this won’t work:

## Topics

### Views

- ``BottomSheet``
- ``BottomSheetHandle``

### Styles

- ``BottomSheetStyle``

This will give you the following warning:

Linking to 'BottomSheet' from a Topics group in 'doc://BottomSheet/documentation/BottomSheet' isn't allowed.

If you have a look at the generated documentation, BottomSheet will show the target’s description instead of the type’s, and tapping it does nothing.

To explicitly link to a type instead of a target, just add the target’s name before the type name, separated with a forward slash:

## Topics

### Views

- ``BottomSheet/BottomSheet``
- ``BottomSheetHandle``

### Styles

- ``BottomSheetStyle``

Adding this prefix will make DocC link correctly to the type instead of the target. However, since it’s easy to forget, you may want to avoid naming your types after the target.

Discussions & More

Please share any ideas, feedback or comments you may have in the Disqus section below, or by replying to this tweet

If you found this text interesting, make sure to follow me on Twitter and Mastodon for more content like this, and to be notified when new content is published.

If you like & want to support my work, please consider sponsoring me on GitHub Sponsors.