Domanda

I know you should not override methods in a category that are defined in the class the category is for. But what about overriding inherited methods. Is that OK?

Specifically, UITableViewController inherits methods like viewWillAppear:, viewWillDisappear, viewDidLoad: and so on, from UIViewController.

So, let's say in a category on UITableViewController, we override those methods inherited from UIViewController.

Is it OK?

As far as I can tell, this will only break if Apple in some future version of UIKit decides to override these methods in UITableViewController.

Are there other reasons not to do this?

EDIT:

So the part about overriding methods in categories in the documentation passed under my radar, so thanks for the answer.

I'll have to solve this with subclassing and possibly extensions.

È stato utile?

Soluzione

Overriding methods in a category is discouraged. See Overriding methods using categories in Objective-C

In my opinion it doesn't matter if this means overriding an inherited or class-defined method. Why should it make a difference? Why not subclass?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top