It's not a secret anymore!
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

Objective-C Categories

Hussein Baghdadi
clojure forum advocate

Joined: Nov 08, 2003
Posts: 3479

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?
David Newton

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.
Marc Peabody
pie sneak

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.
I agree. Here's the link:
subject: Objective-C Categories
It's not a secret anymore!