native
native copied to clipboard
ObjC: Support a constructor for all NSObject subclasses
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);
That would be a good start. I was also thinking of translating every method starting with "init" into a constructor.
Decided to just translate Foo.new1() into Foo(), as Brian suggests. Translating all init methods too would be a bit confusing for users, wouldn't improve ergonomics that much, and might cause a lot more name collisions.