digitalmars.D - Can't get Objective-C class method to compile.
- Jeremie Pelletier (32/36) Dec 30 2015 Hello, I'm trying out the new interface to Objective-C and I
- Jacob Carlborg (8/13) Dec 31 2015 D doesn't support Objective-C classes methods yet. But as a
- Jeremie Pelletier (5/11) Dec 31 2015 Oh, that's good to know! Thanks for the tip :)
Hello, I'm trying out the new interface to Objective-C and I
can't get this to compile:
module main;
extern (Objective-C) {
interface NSObject {
void release() selector("release");
}
interface NSString : NSObject {
const(char)* UTF8String() selector("UTF8String");
}
interface NSProcessInfo : NSObject {
static NSProcessInfo processInfo()
selector("processInfo");
NSString operatingSystemVersionString()
selector("operatingSystemVersionString");
}
}
void main() {
import std.stdio;
auto str =
NSProcessInfo.processInfo.operatingSystemVersionString;
writeln(str.UTF8String);
str.release();
}
I used the following command line:
dmd main.d -L-framework -LFoundation
I'm running the latest dmd (2.069.2) and it exits after printing
this message:
Assertion failed: (ethis), function
objc_callfunc_setupMethodCall, file objc_glue.c, line 276.
Abort trap: 6
This is from the class method call to NSProcessInfo.processInfo.
I've tried without the selector but get a linker error on
__D4main13NSProcessInfo11processInfoYZC4main13NSProcessInfo.
I'm not sure if it is a bug or if I'm not using it correctly so
I'm asking here before opening a bug report :)
Dec 30 2015
On Thursday, 31 December 2015 at 03:43:58 UTC, Jeremie Pelletier wrote:This is from the class method call to NSProcessInfo.processInfo. I've tried without the selector but get a linker error on __D4main13NSProcessInfo11processInfoYZC4main13NSProcessInfo. I'm not sure if it is a bug or if I'm not using it correctly so I'm asking here before opening a bug report :)D doesn't support Objective-C classes methods yet. But as a workaround you can look how it's done with the "alloc" method in the documentation [1]. Declare the method as a non-static method but use the result from "objc_lookUpClass" as the receiver (object). [1] http://dlang.org/spec/objc_interface.html#usage-example
Dec 31 2015
On Thursday, 31 December 2015 at 08:56:07 UTC, Jacob Carlborg wrote:D doesn't support Objective-C classes methods yet. But as a workaround you can look how it's done with the "alloc" method in the documentation [1]. Declare the method as a non-static method but use the result from "objc_lookUpClass" as the receiver (object). [1] http://dlang.org/spec/objc_interface.html#usage-exampleOh, that's good to know! Thanks for the tip :) I'll definitely keep an eye out for the rest of Objective-C support. Adding it was a fantastic idea :)
Dec 31 2015








Jeremie Pelletier <jeremiep gmail.com>