Extending Objective-C from D.
Jeremie Pelletier via Digitalmars-d
digitalmars-d at puremagic.com
Sat Jan 9 02:09:12 PST 2016
Hello, I'm trying to see if I can write a full Cocoa app in D,
and I'm having trouble creating D classes when the underlying
Objective-C interfaces have methods.
It works for the app delegate because it needs to override them,
but for other classes the compiler says the Objective-C methods
aren't implemented in the D subclass.
I was successful in getting a simple application to boot with
console errors about a missing NIB file. Its impressive how much
you can get done so far :D
Now I'm trying to manually create the app and the delegate,
completely bypassing NSApplicationMain with mixed success. Here's
the main function:
auto me = new MyApplication;
auto dg = new MyAppDelegate;
me.setDelegate(dg);
me.run();
I even asserted after instantiating MyApplication it is identical
to NSApplication.sharedApplication (using the objc_lookUpClass
trick to emulate static calls) and they're the same value. The
delegate also creates correctly, just like it did through
NSApplicationMain reading the Info.plist file. neat!
But I crash when calling setDelegate. I marked the methods final
in NSApplication's definition as it was the only thing I found
passing the compiler. Without it I get the missing implementation
errors. I tried to new the interface and that didn't work either.
So I'm at a loss on how to declare this. I could split
NSApplication into the interface to derive from and the one to
call functions on, but that kind of breaks everything and I can't
use one in all definitions and cast to the other in all
implementations, that would be crazy :)
More information about the Digitalmars-d
mailing list