Reputation: 1219
I have a category on NSobject which implements two protocols. In that implementation One of them is fully implemented but the method that complies to the protocol calls a method for the other protocol. What I want to do is to forward the method implentation responsibility to any class which would like to import that category. That means to supress the not implemented method warning and make the compiler complain in the importing class. Is this possible?
Upvotes: 1
Views: 125
Reputation: 8200
As I stated in my comment, when you create a category on NSObject
, then any subclass of NSObject
gets those methods whether or not the subclass has an import statement for the category. So a category doesn't get selectively added to subclasses that import it.
What you could do to achieve what you want is to remove from the category the part where it says you implement the protocols, so that all you have is the methods implemented there. Then the compiler won't complain about your category missing some required protocol methods. Then when somebody has a subclass, they can specify that their subclass implements those protocols, and they can implement the missing methods to make the compiler not complain in their subclass.
Upvotes: 0
Reputation: 237080
You can either make the method @optional or give NSObject a dummy implementation that just gives an error along the lines of "This method must be overridden." There's no way to get a compile-time warning in this situation for some classes that don't implement the method and not for others, though.
Upvotes: 2