如何将“SEL”和“ID”转换为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]; }
如何将“SEL”和“id”转换为string?
调用NSStringFromSelector()
传递您的select器作为其参数来获取select器string,并且使用[parent class]
作为parent
对象的类:
NSString *errorMessage = [NSString stringWithFormat:@"%@ in class %@ doesn't exist!", NSStringFromSelector(selector), [parent class]];