On 10/23/15 11:53 AM, Kagamin wrote:
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();
}

I think this would look better as the official example!

Question is, what does objc_lookUpClass actually return? I'm assuming id. I still don't know what that is in D, void*?

-Steve

Reply via email to