20

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

Community
  • 1
  • 1
wOlVeRiNe
  • 545
  • 1
  • 4
  • 21
  • Not a duplicate of https://stackoverflow.com/questions/862299/ which is asking about the mechanics of how categories work, not what they are. – nevan king Aug 12 '18 at 18:27

2 Answers2

27

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

Ratul Sharker
  • 7,484
  • 4
  • 35
  • 44
Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76
  • 2
    Categories in Objective-C are similar to [Ruby open classes](http://rubylearning.com/satishtalim/ruby_open_classes.html) and [C# extension methods](http://msdn.microsoft.com/en-us/library/vstudio/bb383977.aspx) – Alex Bitek Feb 25 '13 at 14:26
  • Just want to report that the Category in ObjC link no longer exists. – Arc676 Dec 27 '15 at 09:14
  • @Arc676 Categories definitely still exist. – Jared Egan Feb 05 '16 at 02:08
  • Both links are expired now. – Hima May 22 '17 at 07:13
  • Official documentation: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html – mr5 Jun 05 '17 at 03:55
1

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.

Abizern
  • 146,289
  • 39
  • 203
  • 257