Extending Objective-C from D.
Guillaume Piolat via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jan 10 13:51:53 PST 2016
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.
More information about the Digitalmars-d
mailing list