Reputation: 3406
I have the following line of code in my iPhone app:
[[sections allValues] sortedArrayUsingSelector:@selector(sortSectionsBySectionName:)];
which generates a Undeclared selector
warning.
All the objects in the array implements sortSectionsBySectionName:
, so everything works as expected. I would, however, like to get rid of the warning.
Is there any way to tell the compiler that, the objects will indeed implement the selector? casting or something similar?
Any suggestions would be appreciated!
Upvotes: 2
Views: 205
Reputation: 119031
The method used should be publicly visible to the class using it. That generally means either:
sortSectionsBySectionName:
to the .h file of the objects in the array and #import
the .h file in this controllersortSectionsBySectionName:
method thereOnce the compiler can see the existence of the method within the scope you're trying to use it you should be good.
Alternatively, ask the compiler to ignore it:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
[[sections allValues] sortedArrayUsingSelector:@selector(sortSectionsBySectionName:)];
#pragma clang diagnostic pop
but beware that this (and the category approach) could both hide issues that will cause problems at runtime...
Upvotes: 1