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?
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]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With