Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Categories are a way for Objective-C code to add extra methods to a class. There are basically two ways we could handle these in
header-translator
:Emit
extern_methods!
directly on the class (done currently).This breaks when the class is defined in a different library/framework than the category, because of Rust's coherence rules.
Create a trait, and implement that for the class (done in
uikit-sys
, and now byextern_category!
).One problem here is that the category name is not part of the API in Objective-C, so we actually have no stable name to refer to. Relatedly, it's annoying to have to import category traits with confusing names all the time.
Both approaches have issues, so I've tried to strike a nice balance; we now emit
extern_methods!
when the category is defined in the same library/framework as the class, andextern_category!
otherwise. This doesn't completely resolve the issues around categories not having a stable name, but it does somewhat alleviate them.This allows us to fix #531, we now emit the missing key-value coding categories (and other such categories on
NSObject
). This should also help with splittingicrate
up into multiple crates in the future, instead of it being a big monolithic one. Finally, this is required forheader-translator
to work on user-defined categories in the future (see #501).CC @simlay as you've gone with the second approach in
bindgen
's Objective-C support, wanted to hear your thoughts about this combined solution? I note that yours is currently better, since it implements the category trait for subclasses as well.