discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Replacement for descriptionForInstanceMethod:


From: Andreas Höschler
Subject: Re: Replacement for descriptionForInstanceMethod:
Date: Tue, 8 May 2018 19:16:59 +0200

Hi Fred,

You should have a look at GSProtocolGetMethodDescriptionRecursive in Additions/GSObjCRuntime.m. I think this should be able to provide the required functionality.

Thanks a lot. I do

         NSMethodSignature *objcSignature = nil;
         #ifdef __APPLE__
           {
            struct objc_method_description *methodDescription = NULL;
            methodDescription = [_protocol descriptionForInstanceMethod:aSelector];
            if (methodDescription == NULL) methodDescription = [_protocol descriptionForClassMethod:aSelector];
            if (methodDescription != NULL) types = methodDescription->types;
           }
         #else
           {
            struct objc_method_description desc;
            desc = GSProtocolGetMethodDescriptionRecursive(_protocol, aSelector, YES, YES);
            if (desc.name == NULL && desc.types == NULL)
              {
               desc = GSProtocolGetMethodDescriptionRecursive(_protocol, aSelector, YES, NO);
              }
            types = desc.types;
           }
         #endif
         if (types) objcSignature = [NSMethodSignature signatureWithObjCTypes:types];

now. The Apple part works on Macs and with my ancient GNUstep tree. I do not know yet, whether the non-Apple part works on Ubuntu (current GNUstep) but will try once the SIGSEGV problem is figured out. :-)

It's a little surprising to me why

Protocol * _protocol = @protocol(TestProtocol);
SEL aSelector = @selector(doIt);
struct objc_method_description _methodDescription = protocol_getMethodDescription(_protocol, aSelector, NO, YES);
if (_methodDescription.name == NULL) _methodDescription = protocol_getMethodDescription(_protocol, aSelector, NO, NO);
NSLog(@"_methodDescription.name %@", NSStringFromSelector(_methodDescription.name));

does not work on Apple as I understood this was the recommended way to do it now!? But it simply does not work, therefore reverting back back to the deprecated approach (deprecated descriptionForInstanceMethod: method of Protocol).

Thanks so much,

 Andreas





reply via email to

[Prev in Thread] Current Thread [Next in Thread]