ObjC method type encoding string for a method with a Block parameter

I'm reading Apple's article on Objective-C runtime type encoding strings , but I don't understand how to code a method with a Block parameter.

For example, I have this:

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler 

      

I don't understand what to use for (void(^)())completionHandler

+3


source to share


2 answers


All types of objects @

. So I would expect this because blocks are objects in Objective-C.



However, you might be asking yourself about the runtime method_getTypeEncoding()

.

+1


source


When in doubt, use the directive @encode

:

typedef void(^CompletionHandler)(void);

char *encoded = @encode(CompletionHandler);
NSLog(@"Encoded: %s", encoded);

      

displays @?

.



To quote a link to your documentation:

@ Object (statically typed or typed identifier)
? Unknown type (among other things, this code is used for function pointers)

+1


source







All Articles