For me, Objective-C's ability to react, describe, and mess-with its surroundings is where it's at. This starts, at a fundamental level, with an unwavering ability to refer to _cmd
, at any point, and get the current SEL
. From there, it is up to you what NSInvocation
incantations or runtime chicanery you choose to partake in.
Now, inside a block, you can still call _cmd
and get a vague description of the current "context", i.e.
__30-[RoomController awakeFromNib]_block_invoke123RoomController
Descriptive? Yes. Informative? Okay... But not so useful. How to do I get dynamic and accurate runtime info inside a block, specifically the calling signature, args, etc.?
I have found a useful little method to "describe" a block ahead of time that gives a good example of the type of information I am hoping to garner INSIDE the block.
typedef void(^blockHead)(NSString*);
blockHead v = ^(NSString*sandy) { NSLog(@"damnDog",nil); };
Log([v blockDescription]);
[v blockDescription] = <NSMethodSignature: 0x7fd6fabc44d0>
number of arguments = 2
frame size = 224
is special struct return? NO
return value: -------- -------- -------- --------
type encoding (v) 'v'
flags {}
modifiers {}
frame {offset = 0, offset adjust = 0, size = 0, size adjust = 0}
memory {offset = 0, size = 0}
argument 0: -------- -------- -------- --------
type encoding (@) '@?'
flags {isObject, isBlock}
modifiers {}
frame {offset = 0, offset adjust = 0, size = 8, size adjust = 0}
memory {offset = 0, size = 8}
argument 1: -------- -------- -------- --------
type encoding (@) '@"NSString"'
flags {isObject}
modifiers {}
frame {offset = 8, offset adjust = 0, size = 8, size adjust = 0}
memory {offset = 0, size = 8}
class 'NSString'