I Did It! Calling D Library from Objective C in XCode on OSX

Mike McKee via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Dec 14 11:20:41 PST 2015


On Monday, 14 December 2015 at 18:13:02 UTC, Mike McKee wrote:
> I think I installed dmd through homebrew. I don't know how to 
> update it -- I'm still green when it comes to homebrew and only 
> know apt-get from Ubuntu Linux.

Oh, I found I could do:

$ sudo brew update
$ sudo brew upgrade dmd

Now it generates this error:

$ dmd -m64 -L-framework -LFoundation test.d
test.d(6): Error: undefined identifier 'selector'
test.d(12): Error: undefined identifier 'selector'
test.d(13): Error: undefined identifier 'selector'

Here's the source I'm trying to compile, and evidently it doesn't 
like @selector for some reason:

// test.d
module main;

extern (Objective-C)
interface Class
{
     NSString alloc() @selector("alloc");
}

extern (Objective-C)
interface NSString
{
     NSString initWithUTF8String(in char* str) 
@selector("initWithUTF8String:");
     void release() @selector("release");
}

extern (C) void NSLog(NSString, ...);
extern (C) Class objc_lookUpClass(in char* name);

void main()
{
     auto cls = objc_lookUpClass("NSString");
     auto str = cls.alloc().initWithUTF8String("Hello World!");
     NSLog(str);
     str.release();
}



More information about the Digitalmars-d-learn mailing list