On Thursday, 14 December 2017 at 19:10:26 UTC, mrphobby wrote:
On Thursday, 14 December 2017 at 14:07:25 UTC, Adam D. Ruppe
wrote:
I was playing with this myself based on Jacob's code and made
it look like this:
extern (Objective-C) interface ViewController :
NSViewController {
extern (C)
@ObjCMethodOverride("loadView")
static void loadView(ViewController self, SEL sel) {
printf("loadView\n");
}
extern (C)
@ObjCMethodOverride("viewDidLoad")
static void viewDidLoad(ViewController self, SEL sel) {
printf("viewDidLoad\n");
}
ViewController init() @selector("init");
mixin RegisterObjCClass;
}
This looks pretty awesome and very much like something I was
looking for. Would really appreciate if you could share your
work. Otherwise I'll have to roll up my sleeves and try hacking
it on my own :)
Ok, I finally had some time to work this out today. Thanks to the
ideas posted here I was able to wrap something up despite my very
limited knowledge of D and its compile time features :)
Basically this is what your classes will look like:
extern (Objective-C)
@ObjCSuperClass("NSObject")
interface AppDelegate : NSApplicationDelegate {
mixin ObjCClass;
AppDelegate init() @selector("init");
extern (C):
@ObjCMethod("applicationDidFinishLaunching:")
static void applicationDidFinishLaunching(AppDelegate self, SEL
sel, NSNotification notification) {
writefln("applicationDidFinishLaunching");
}
}
In this case I needed to add the explicit superclass attribute
since NSApplicationDelegate is a protocol and not a class. If
your object inherits from an interface representing a regular
Objective-C class you don't need this.
The actual registration and setup principle is based on Jacobs
code and I added stuff to handle the attributes. Obviously you
need declarations for Objective-C runtime calls but you can find
those in Jacobs example source as well.
Anyway, hope this helps. Feel free to fork and improve!
https://gist.github.com/mrphobby/a247deb15d38aea86b3346079f32ce58