I have a category for each of my NSManagedObject subclasses, where factory methods sit, so that they are not lost when automatically regenerating the class files. So that I don’t need to know what subclass of NSManagedObject I’m using at runtime, each subclass has the same name for its factory method, e.g.
+ (id)objectWithInfo:(NSDictionary *)info inManagedObjectContext:(NSManagedObjectContext *)context;
(For clarity, in this example suppose there is an entity deriving from NSManagedObject called Item, with generated files Item.m and Item.h, and my own category with files Item+Factory.m and Item+Factory.h, where the method above resides).
In Xcode 4.3 this generates no warning: but Xcode 4.4 (and above flag it as a warning:
(null): Meta method ‘objectWithInfo:inManagedObjectContext:’ in
category from …Item+Factory.o conflicts with same method from
another category
Now, I’m well aware of the dangers of overloading a method in a category, it’s a Bad Thing. What I’m doing here, however, is simply treating objects as a more general class than they are, which as fas as I’m aware is sensible.
Is what I’m doing bad? Or is there a different way to declare my methods to remove the warning?
To answer my own question:
I was redeclaring the method in the header of each subclass. Declaring once in the superclass sorted it.
Additionally, moving all +Factory.h #imports into the precompiled header (and removing elsewhere) vastly reduces confusion and additional warnings.
Thanks to Paul.s for making me think along those lines.