objective-c – 如何确定对象是否实现了特定方法?
栏目: Objective-C · 发布时间: 7年前
内容简介:翻译自:https://stackoverflow.com/questions/1103895/how-can-i-find-out-if-an-object-implements-a-particular-method
我正在迭代包含许多不同类型对象的NSArray.有很多方法可以确定对象是什么类.但是,我无法找到一个好方法来确定对象是否可以实现特定的功能.我可以将它放在try-catch中,但即使我正在捕获错误,它仍会在控制台中输出错误消息.有一个更好的方法吗?
简单的例子:
@try {
if ([element lowercaseString]) {
//do something
}
}
@catch (id theException) {
// do something else
}
respondsToSelector:
消息.提供的代码就像 if ([element respondsToSelector:@selector(lowercaseString)]) {
// ... do work
}
翻译自:https://stackoverflow.com/questions/1103895/how-can-i-find-out-if-an-object-implements-a-particular-method
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
An Introduction to the Analysis of Algorithms
Robert Sedgewick、Philippe Flajolet / Addison-Wesley Professional / 1995-12-10 / CAD 67.99
This book is a thorough overview of the primary techniques and models used in the mathematical analysis of algorithms. The first half of the book draws upon classical mathematical material from discre......一起来看看 《An Introduction to the Analysis of Algorithms》 这本书的介绍吧!