If you need to add a method to an existing class, perhaps, to add functionality to make it easier to do something in your own application, the easiest way is to use a category.
The syntax to declare a category uses the @interface keyword, just like a standard Objective-C class description, but does not indicate any inheritance from a subclass. Instead, it specifies the name of the category in parentheses, like this:
Syntax @interface ClassName (CategoryName) @end
Characteristics of category
- A category can be declared for any class, even if you don’t have the original implementation source code.
- Any methods that you declare in a category will be available to all instances of the original class, as well as any subclasses of the original class.
- At runtime, there’s no difference between a method added by a category and one that is implemented by the original class.
In our example, since we just have a single class, we have not included any header files, in such a case we should include the header files