0

Possible Duplicate:
Difference between inheritance and Categories in Objective-c
What’s the difference and use of categories and inheritance?

thanks for your reply,for example we have nsstring class if we want to add methods to that class there is no need to create category for that,just we can subclass it but why we are using categories?Please help on this

Community
  • 1
  • 1
user1007352
  • 11
  • 1
  • 1
  • 1
    Is there any difference to your previous question? http://stackoverflow.com/questions/13344075/whats-the-difference-and-use-of-categories-and-inheritance – vikingosegundo Nov 12 '12 at 13:49
  • ...which was a duplicate of yet another question. – woz Nov 12 '12 at 13:50

1 Answers1

10

Category adds some extra functionality to specific class (for example NSString). You don't need to declare the Object with that specific class name. You only import that category and all the Object implicitly become instance of the category, all the implementation is now available to them.

Where when subclassing, (sometimes you intently need to override the existing behavior/methods or you can add extra functionality too.) you explicitly declare that Object with the type like

MyCustomString *string;

and then all the methods become visible.

Adil Soomro
  • 37,609
  • 9
  • 103
  • 153