Vision
Kagamin via Digitalmars-d
digitalmars-d at puremagic.com
Fri Oct 23 08:53:35 PDT 2015
On Friday, 23 October 2015 at 12:44:03 UTC, Steven Schveighoffer
wrote:
> The example looks terrible -- objc_lookUpClass which only gets
> a class that can alloc an NSString? Can this be done better? An
> objective-c developer that is not too familiar with D would be
> very disappointed in this binding.
A little of massage and you get:
struct ClassStorage(C)
{
alias lookUp this;
C lookUp() immutable
{
return cast(C)objc_lookUpClass(C.stringof);
}
}
immutable ClassStorage!NSString cNSString;
C alloc(C)()
{
immutable ClassStorage!C c;
return c.alloc();
}
void main()
{
auto str = cNSString.alloc.initWithUTF8String("Hello World!");
auto str1 = alloc!NSString.initWithUTF8String("Hello World!");
NSLog(str);
str.release();
str1.release();
}
More information about the Digitalmars-d
mailing list