开发者

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

开发者 https://www.devze.com 2023-01-31 23:14 出处:网络
id parent; SEL selector; // lot\'s of code... if ([parent respondsToSelector:selector]) { } else { // This doesn\'t w开发者_StackOverflow中文版ork:
id parent;
SEL selector;

// lot's of code...

if ([parent respondsToSelector:selector]) {

}
else {
    // This doesn't w开发者_StackOverflow中文版ork:
    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]];
0

精彩评论

暂无评论...
验证码 换一张
取 消