You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
cc @d-ronnqvist who was also looking into this last week
I think David wanted a version that force-casted the mixin to the mixin type if the key was present, and/or provide a debug assertion on it, but Max's patch definitely fits the spirit of what i was asking for originally.
I'm going to close this issue as resolved, but @d-ronnqvist can chime in with more details if he wants.
At one point I was thinking that perhaps the subscript should assert in debug builds that the generic mix-in for a given key is of that generic type. As far as I'm aware this should always hold true for all the built-in mix-ins.
That said, we can always consider something like that in the future if we run into issues with mix-ins unexpectedly returning nil due to key collisions or data format version differences.
Additional Detail from JIRA
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:In fact, Swift-DocC already defines something similar, as an extension on mixin dictionaries themselves:
Adding one of these methods to SymbolKit and encouraging its use throughout Swift-DocC would make its codebase much more readable.
The text was updated successfully, but these errors were encountered: