Using CTBlockDescription , you can get all the necessary runtime information in the form of NSMethodSignature . The use is simple:
NSString * (^block)(int, NSArray *) = ^NSString * (int i, NSArray * a){ return @"Oh, yeah!"; }; NSMethodSignature *signature = [[[CTBlockDescription alloc] initWithBlock:block] blockSignature]; NSLog(@"signature %@", [signature debugDescription]);
The following signature will be displayed here:
signature <NSMethodSignature: 0x6844900> number of arguments = 3 frame size = 12 is special struct return? NO return value: -------- -------- -------- -------- type encoding (@) '@' flags {isObject} modifiers {} frame {offset = 0, offset adjust = 0, size = 4, size adjust = 0} memory {offset = 0, size = 4} argument 0: -------- -------- -------- -------- type encoding (@) '@?' flags {isObject} modifiers {} frame {offset = 0, offset adjust = 0, size = 4, size adjust = 0} memory {offset = 0, size = 4} argument 1: -------- -------- -------- -------- type encoding (i) 'i' flags {isSigned} modifiers {} frame {offset = 4, offset adjust = 0, size = 4, size adjust = 0} memory {offset = 0, size = 4} argument 2: -------- -------- -------- -------- type encoding (@) '@' flags {isObject} modifiers {} frame {offset = 8, offset adjust = 0, size = 4, size adjust = 0} memory {offset = 0, size = 4}
source share