Frameworks, categories and shared namespace
Adam R. Maxwell
amaxwell at mac.com
Sat Jun 7 08:25:26 PDT 2008
On Jun 7, 2008, at 5:22 AM, Christiaan Hofman wrote:
> So now to the main question. What is the proper way to avoid
> conflicts in these situations? It seems to me that the obvious way
> to define a (convenience) category in the usual way is actually
> wrong in this situation. Some solutions I can think of is to define
> method names starting with a unique prefix. It's a bit annoying
> though. Another possibility is to use utility functions (with names
> starting with a unique prefix) rather than methods in a category.
> that's also a bit annoying, as you abandon the OOP. So what is the
> proper way to work around this Obj-C limitation?
I use something like xx_ prepended to method names in that case, but I
borrowed the idea from Apple. Some of the runtime exploring tools
show that there's an ABCompare protocol on NSObject, and that uses
_abCompare as a prefix. NSURL has a bunch of category additions with
_web_ and _webkit_ prefixes.
If you're adding a lot of methods to an Apple-supplied class, I think
it's preferable to use a subclass, framework or not (but that doesn't
work with some objects, e.g. singletons).
--
Adam
More information about the MacOSX-dev
mailing list