How to convert "SEL" and "id" to NSString?
21,081
Call NSStringFromSelector()
passing your selector as its argument to get the selector string, and use [parent class]
for the parent
object's class:
NSString *errorMessage = [NSString stringWithFormat:@"%@ in class %@ doesn't exist!",
NSStringFromSelector(selector),
[parent class]];
Comments
-
Manni almost 4 years
id parent; SEL selector; // lot's of code... if ([parent respondsToSelector:selector]) { } else { // This doesn't work: NSString *errorMessage = [NSString stringWithFormat:@"%@ in class %@ doesn't exist!", selector, parent]; }
How do I convert "SEL" and "id" to a String?
-
Takagi almost 12 yearsThe opposite way is: SEL aSelector = NSSelectorFromString(@"tapMeAction:");
-
owen gerig over 11 yearsjust wanted to point out that "@%s",_cmd use to work (and still does) but now post a warning. this seems to be the proper way
-
Benji XVI over 10 yearsNote - the format of the string returned by
NSStringFromSelector
is simply the selector, e.g.@"setTitle:"
. i.e. it has no@selector(~)
wrapping etc.