我的iPhone应用程序中包含以下代码行:
[[sections allValues] sortedArrayUsingSelector:@selector(sortSectionsBySectionName:)];
会产生
Undeclared selector
警告。数组中的所有对象都实现了
sortSectionsBySectionName:
,因此一切都按预期进行。但是,我想摆脱警告。有什么办法告诉编译器,这些对象确实会实现选择器?铸造或类似的东西?
任何建议,将不胜感激!
最佳答案
使用的方法对于使用它的类应该是公开可见的。这通常意味着:
sortSectionsBySectionName:
,在此控制器中将.h文件添加#import
sortSectionsBySectionName:
方法一旦编译器在您要使用的范围内看到该方法的存在,您就应该很好。
或者,要求编译器忽略它:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
[[sections allValues] sortedArrayUsingSelector:@selector(sortSectionsBySectionName:)];
#pragma clang diagnostic pop
但请注意,这种方法(以及类别方法)都可能隐藏会在运行时引起问题的问题...