dart-lang / native

Dart packages related to FFI and native assets bundling.
BSD 3-Clause "New" or "Revised" License
102 stars 35 forks source link

[vm/ffi] ObjC: Make it possible to subclass/implement ObjC classes/protocols #1196

Open mkustermann opened 2 years ago

mkustermann commented 2 years ago

There's use cases where it would be very convenient to make subclasses of ObjC classes (e.g. see sub-classing NSOperationQueue) and doing so in Dart.

Having this ability would avoid the need to write native code (and thereby not require changes to dart:ffi or adding flutter-specific plugins) - it could be done purely in Dart .

The most convenient way would be have Dart syntax for making subclasses of ObjC, possibly with some language restrictions and kernel lowering - similar to how the pure C-based FFI support is done.

Though a simpler way to get started would be providing utilities to procedurally lookup classes, create classes, add methods, ... (see objc_allocateClassPair, objc_addmethod)

/cc @brianquinlan @mraleph @dcharkes

brianquinlan commented 1 year ago

A wrote a small doc explaining why this important and how it might work.

mraleph commented 3 weeks ago

Here is a possible way to do that: https://gist.github.com/mraleph/5971f1904d474526066dc3c792c9436e, just leaving it here for completeness.

I think macros can be a good way to cut on the boilerplate and do a lot of this in pure Dart.