Is it safe to override a category-defined method in Objective-C?

I have a class structure of type UIViewControllerSubclass : UIViewController , where the only function of the UIViewControllerSubclass is #import UIViewController+Category.h . The reason I added methods to the category is because I can also make UITableViewControllerSubclass : UITableViewController , which will be #import UIViewController+Category.h . As we all know, do not repeat yourself.

Now suppose that UIViewController + Category.h has the structure:

 @interface UIViewController(Category) - (void) method1; - (void) method2; @end 

How safe is it to create a UIViewControllerSubclassSubclass : UIViewControllerSubclass , which will override method1 ? I suppose this will work due to the transmission of an Objective-C message, but for some reason my intuition tells me that I am doing it wrong.

+8
objective-c objective-c-category
source share
1 answer

Everything should work fine, as the category applies to the UIViewController , so all instances of the UIViewController , including subclasses, will have access to these methods. Nothing is dangerous there; that both categories are intended to be applied.

+7
source share

All Articles