将 nil 传递给 PerformSelector
我正在使用 NSObject 的 PerformSelector 方法来调用基于运行时确定的变量字符串的方法。
[self performSelector:NSSelectorFromString(methodName)];
方法调用在循环内。但是,在某些循环迭代中,我不想执行任何操作,并且 methodName
可能为零。 看来performSelector消息不接受nil作为参数。当我不想让 PerformSelector 执行任何操作时我该怎么办?
编辑: 我应该说得更清楚。现在,我正在设置 methodName = @"doNothing"
- 顾名思义 - 当我希望它为零时。我想知道是否有比这更优雅的解决方案,或者只是放置一个 if 块。 我想我的问题是 - 是否有空类型选择器?
I am using the NSObject's performSelector method to call a method based on a variable string determined at runtime.
[self performSelector:NSSelectorFromString(methodName)];
The method call is within a loop. However, on some loop iterations I don't want to do anything and methodName
may be nil.
It seems that the performSelector message does not take nil as an argument. What can I do when i don't want performSelector to perform any actions?
Edit:
I should have been more clear. For now, i am setting methodName = @"doNothing"
- which is what is name implies - when I want it to be nil. I want to know if there is a more elegant solution than this, or just putting an if block.
I guess my question is - Is there a null type selector?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查是否为
nil
?Check to see if it's
nil
?您可能正在寻找这个 -
You may be looking for this -