gpt4 book ai didi

ios - 如何将 "SEL"和 "id"转换为 NSString?

转载 作者:IT老高 更新时间:2023-10-28 11:49:08 29 4
gpt4 key购买 nike

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”转换为字符串?

最佳答案

调用 NSStringFromSelector()将您的选择器作为其参数传递以获取选择器字符串,并使用 [parent class] 作为 parent 对象的类:

NSString *errorMessage = [NSString stringWithFormat:@"%@ in class %@ doesn't exist!",
NSStringFromSelector(selector),
[parent class]];

关于ios - 如何将 "SEL"和 "id"转换为 NSString?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4490082/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com