-
Notifications
You must be signed in to change notification settings - Fork 44
Description
| Previous ID | SR-16111 |
| Radar | None |
| Original Reporter | @QuietMisdreavus |
| Type | Improvement |
Additional Detail from JIRA
| Votes | 0 |
| Component/s | Swift-DocC |
| Labels | Improvement |
| Assignee | None |
| Priority | Medium |
md5: 9c3463d48a54fbd06e0e7b6bba7d89d2
Issue Description:
SymbolKit currently defines optional data fields for symbols and relationships as a set of "mixins", which is represented as a map from a "mixin key" to the parsed value of that mixin. Swift-DocC uses these mixins for various uses, but checking for a value and reading it out is a bit cumbersome. For example, this is how Swift-DocC loads availability information from a symbol:
if var availability = symbol.mixins[SymbolGraph.Symbol.Availability.mixinKey] as? SymbolGraph.Symbol.Availability
This could be greatly simplified into some kind of getMixin method on symbols and relationships in SymbolKit. It could look something like this:
func getMixin<T>() -> T? where T: Mixin {
self.mixins[T.mixinKey] as? T
}In fact, Swift-DocC already defines something similar, as an extension on mixin dictionaries themselves:
extension Dictionary where Key == String, Value == Mixin {
func getValueIfPresent<T>(for mixinType: T.Type) -> T? where T: Mixin {
return self[mixinType.mixinKey] as? T
}
}Adding one of these methods to SymbolKit and encouraging its use throughout Swift-DocC would make its codebase much more readable.