Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert "SEL" and "id" to NSString?

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?

like image 693
Manni Avatar asked Dec 20 '10 13:12

Manni


1 Answers

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]];
like image 199
BoltClock Avatar answered Nov 20 '22 14:11

BoltClock