Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to print SEL action?

For example, I want to trace the actions sent to my canPeformAction and they are too numerous to display at each occurrence with a "hover" in the debugger. Therefore, I want to trace to the log and examine it after my test cycle.

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    NSLog(@"%s: sender=%@", __FUNCTION__, sender, action);
}
like image 624
mobibob Avatar asked May 04 '12 18:05

mobibob


2 Answers

You want

NSLog(@"%s: sender=%@, selector=%s", __FUNCTION__, sender,sel_getName(action));
like image 113
Dave.B Avatar answered Oct 10 '22 04:10

Dave.B


Use NSStringFromSelector to easily get a printable name of the Selector.

NSStringFromSelector(action)

NSString * NSStringFromSelector ( SEL aSelector );

Returns a string representation of a given selector.

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    NSLog(@"Action: %@", NSStringFromSelector(action));
}
like image 38
pkamb Avatar answered Oct 10 '22 03:10

pkamb