objective c - If object respondsTo still throws warning -
I am working on a project where I have a class in which UIView
property I also define a class which is a subclass of UIView
that defines a certain method if I have the following code, I get a warning when I will create:
// In this example, MyView is the UIView property which * * could include a UIView or // my subclass-UIView which is my law If the method does ([myView responds: TiceAcclator: @Sylector (Merimath)] {[myView myMethod]}
The warning is "UIView can not answer" -myMethod " It's a warning that the app is not designed to stop creation, but I'm trying to understand how to deal with it. Is this the right way to do it? Is there any way to stop this warning?
Warning only because compile Do not know that this view is your custom sub-class. Of course, at runtime this will work fine, because it will be a subclass, you have two options to fix it:
[MyView performSelector: @selector (myMethod)];
(hence the compiler method does not check the call at all)
Or, better:
[MyViewClass *] MyView myMethod ];
This way the compiler works in such a way that the object is actually your sub-subview (after examining the course).
For that matter, it can understand how to check your class instead of the method:
If ([myView is KindOfClass: [MyViewClass class]]) {...
Comments
Post a Comment