wood burning stoves*
The moose likes Other Languages and the fly likes Objective-C Categories Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "Objective-C Categories" Watch "Objective-C Categories" New topic
Author

Objective-C Categories

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

Hey,
Categories in Objective-C are used to add additional methods to existing classes without subclassing them.
Does this mean that Objective-C support some sort of Meta-programming?
Thanks.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That's not what I'd typically consider meta-programming, which to me means things like macros ("programs that write programs") or meta-object protocols.

http://en.wikipedia.org/wiki/Metaprogramming
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

It's basically monkeypatching.

This is incredibly valuable in Objective-C, often because many of the Cocoa APIs are... not everything they could be. If you're sick of passing the same parameter to some method or having to call 3 or more methods together to perform a single unit of work, just create your own method to make things easier.

You'll likely carry your Categories like a tool belt from project to project. The more conveniences you give yourself, the better your overall productivity.


A good workman is known by his tools.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Objective-C Categories