What is “category” in Objective-C?

24,902

Solution 1

A category allows you to add methods to an existing class—even to one for which you do not have the source.

Categories are a powerful feature that allows you to extend the functionality of existing classes without subclassing

Check the apple doc for the Category in Objective-C

Solution 2

There is a section in the Objective-C 2.0 programming Language document about Categories and Extensions.

As you are just getting started it's a good doc to have on hand to look things up.

There is also a section on Categories in the Cocoa Core Competencies document, which is easier to get started with, and also has a lot of useful information for the beginner.

Share:
24,902
wOlVeRiNe
Author by

wOlVeRiNe

,.,.,.,.,.,.,.,.,.,.,.,.,

Updated on April 07, 2020

Comments

  • wOlVeRiNe
    wOlVeRiNe about 4 years

    Possible Duplicate:
    How does a category work in Objective-C?

    I am just getting started with Objective-C and was wondering when and where am i supposed to use category in objective C. is it a class or a protocol? An explanatory example would be of great help. Thanks

  • Alex Bitek
    Alex Bitek about 11 years
    Categories in Objective-C are similar to Ruby open classes and C# extension methods
  • Basil Bourque
    Basil Bourque over 10 years
    That first link is now obsolete. Apple redirects to listing of documentation.
  • Arc676
    Arc676 over 8 years
    Just want to report that the Category in ObjC link no longer exists.
  • Jared Egan
    Jared Egan over 8 years
    @Arc676 Categories definitely still exist.
  • Hima
    Hima almost 7 years
    Both links are expired now.
  • mr5
    mr5 almost 7 years