GUI program on Mac OS in D?

mrphobby mrp at spinrock.net
Mon Feb 5 15:49:41 UTC 2018


On Thursday, 21 December 2017 at 17:56:54 UTC, mrphobby wrote:
>
> Thanks for sharing! Your solution is more complete for sure. I 
> think I will borrow a few ideas here :)

I've been playing around with this a bit and it works pretty 
well. One thing that bothers me is the handling of NSString. I 
came up with the following class to handle strings and make sure 
they do not leak. But maybe there is a nicer way to handle this 
in D?

class NSStringRef {
public:
     this(string s) {
         str_ = 
NSString.alloc.initWithBytes(cast(immutable(ubyte)*) s.ptr,
                                             s.length,
                                             
NSStringEncoding.NSUTF8StringEncoding);
     }

     ~this() {
         str_.release();
     }

     NSString str() @property {
         return str_;
     }

private:
     NSString str_;
}

And then you have to use it like this:

     NSStringRef s = new NSStringRef("Hello");
     NSLog(s.str);

Ideally I would like to write code more like this (without 
leaking the NSString):

     NSLog("Hello".nsstring);

Surely this must be possible in D somehow? :)


More information about the Digitalmars-d-learn mailing list