Linking DocC to package named types
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.
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
If you found this interesting and would like to share your thoughts, please comment in the Disqus section below or reply to this tweet.
Follow on Twitter and Mastodon to be notified when new content & articles are published.