Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document a supported pattern for a Dart equivalent to Obj-C's @selector(...) #1580

Open
stuartmorgan opened this issue Sep 18, 2024 · 2 comments

Comments

@stuartmorgan
Copy link

Trying to convert some CADisplayLink code to Dart, I realized that it wasn't obvious how to interact with APIs that use the target:selector: pattern (like +[CADisplayLink displayLinkWithTarget:selector:). Since there are no docs for it, I generated it and looked at the output, and saw that the type is ffi.Pointer<objc.ObjCSelector>. Okay, so how do I make one? Jumping to the definition (in pkg:objective_c) just gives me:

typedef ObjCSelector = _ObjCSelector;

final class _ObjCSelector extends ffi.Opaque {}

Which is not helpful. The only answer I'm aware of to that question is pkg:objective_c's registerName, but:

  1. I only know that is there is because I had previously dug all the way into the generated bindings to make my own manual bindings as workarounds for ffigen bugs (e.g., protocol methods at the time), and
  2. registerName's (only) documentation is /// Only for use by ffigen bindings..

While this isn't a super common pattern in Apple SDKs, especially since newer code generally uses blocks instead, it is around, so we should have a clear support path for it.

@stuartmorgan
Copy link
Author

Oh, a much more common use case for this would be respondsToSelector: for optional protocol methods.

@liamappelbe
Copy link
Contributor

I'll make registerName public and maybe rename it. Might also be convenient to add a string extension method: "foo:bar:".toSelector(). A heavier change would be to add some sort of Selector class to wrap Pointer<ObjCSelector>, but I don't see a need for it, and this would require special casing in ffigen to use the wrapper class in place of the raw pointer.

@liamappelbe liamappelbe added this to the ffigen 15.0.0 milestone Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests

2 participants