Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can category methods be overridden? IOS

I am trying to plan how to add a couple methods to all instances of certain objects. I think adding a category to the parent object(UIViewController) would work for what I want to do, but can I override a method added this way? Most of the time the subclasses will use the default methods but I do know I will need to override the method at least once.

Also what other methods should I consider for what I am trying to do?

Example of what I am trying to do:

I have a set of Objects that act like pages of a journal. These pages are subclasses of UIViewControllers. I want to add methods for loading, saving, and similar. In a journal class(Subclass of NSObject) I have an array storing instances of each Journal page. I want it so I can select a page from the array and run on of the methods without having to know the specific object class as they all should have the methods.

like image 294
Lost Sorcerer Avatar asked Jul 16 '12 17:07

Lost Sorcerer


1 Answers

Short answer: yes, you can. For purposes of inheritance category methods on a superclass are treated like methods that are actually defined in the superclass, and can be overridden in the same way.

like image 105
Ethan Holshouser Avatar answered Sep 22 '22 12:09

Ethan Holshouser