On Sunday, 10 January 2016 at 21:51:53 UTC, Guillaume Piolat wrote:
On Saturday, 9 January 2016 at 10:09:12 UTC, Jeremie Pelletier wrote:
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.


If you are looking to implement/override Obj-C methods in D, I have done it here deriving from NSView
https://github.com/p0nce/dplug/blob/master/window/dplug/window/cocoawindow.d#L426

Using the Obj-C runtime, the D object declares a new class object, populates it with methods (inverse mapping is done with an instance variable containing "this"). Ugly, but works.

Example of a method callback: https://github.com/p0nce/dplug/blob/master/window/dplug/window/cocoawindow.d#L499 Do not forget to prepend the callback arguments with id and selector.

Sweet! I can at least get started while the full DIP gets implemented :)

I already have the Metal bindings more or less ready to publish, I'll try to work on the Cocoa ones this weekend and see how much I can progress!

Oh by the way, I see the DIP declares blocks with the __block keyword, shouldn't it be better to reuse delegate with extern(Objective-C) ? Feels cleaner and more consistent with the rest of the language to me.

Reply via email to