dart-lang / native

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

ObjC: Support a constructor for all NSObject subclasses #259

Open brianquinlan opened 2 years ago

brianquinlan commented 2 years ago

NSObject has a new class method that is equivalent to [[class alloc] init] but calling it is not intuitive because new is a keyword in Dart.

Maybe we could have a special case like this:

class MyClass extends NSObject {
  factory MyClass(MyLib lib) {
    return castFrom(new1(lib));
  }

So you can write:

final c = MyClass(lib);

instead of:

final c = MyClass.new1(lib);
liamappelbe commented 2 years ago

That would be a good start. I was also thinking of translating every method starting with "init" into a constructor.