In this post, let’s take a quick 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``
Addint this prefix will make DocC link correctly to the type instead of the target. However, since it’s easy to forget and you may link quite a lot to a type with the same name as the target (since it’s probably the main type), you may want to avoid naming your types after the target.
I hope that you found this post interesting. I would love to hear your thoughts and feedback, so feel free to comment in the Disqus section below or in this tweet.