Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode 4.5 warns about method name conflicts between Categories for parent/child classes

I'm working on a project that was originally built in XCode 4.0, and then migrated to using XCode 4.2. Now I've tested out migrating to XCode 4.5, and I'm getting a ton of warnings like below...

instance method 'values' in category from <pathToTheFile>/HistoryObject+extras.o conflicts with same method from another category

These warnings never appeared in previous versions of XCode, and the code hasn't changed.

The project is set at iOS 4.3 for the Deployment Target.

So, we have from a previous developer a bunch of DAO type classes that I believe were auto-generated from CoreData, and then each of these classes has a Category that extends it to implement certain methods. I'll give an example...

We have a base class named LisaObject that inherits from NSManagedObject, and it has a Category named LisaObject+extras. In LisaObject+extras, there is a method named "values" that returns an NSMutableDictionary.

We then have a class named HistoryObject that inherits from LisaObject. There is also a Category for HistoryObject that is named HistroyObject+extras. This Category also has a method named "values". In the HistoryObject+extras values method, it calls [super values], and then checks for some conditions and sets some additional values in the dictionary that aren't set in the base class method.

We then have a class named LessonStatusObject that inherits from HistoryObject, and it too has a Category named LessonStatusObject+extras, which has a method named values. This values method also calls [super values] and then does some additional work on the returned dictionary.

For each of these "values" methods, we get a warning at compile time like the one shown above where it says the Category has a method with a conflicting name.

I have a few questions about this.

First, could this implementation cause any legitimate problems, or are these warnings generally benign? I've tried to think of how this implementation could cause an ambiguity at runtime, but I don't see how that could happen.

Second, is there something that I should do to fix these warnings (and I don't mean just make them stop appearing; I mean fix the cause)? Is there some other way we should be going about this?

Also, why would XCode 4.2 not warn about this, but XCode 4.5 does warn?

Am I misunderstanding something about Categories? I mean, if the "values" method was actually part of the each class implementation, it wouldn't be a problem to override them the way we do, but the compiler seems to be complaining simply because these are Categories. Is there anything unsafe about this?

Any advice is much appreciated.

EDIT: Just to provide more information... When we were using XCode 4.2, the project had the compiler set to Apple LLVM Compiler 3.0. Now when I open the project in XCode 4.5, it has the compiler set to Apple LLVM Compiler 4.1.

like image 209
Jim Avatar asked Nov 14 '12 22:11

Jim


2 Answers

I had this same annoying issue and it turned out that I had accidentally included that category's .m file instead of the .h file in one of my VC's code. Correcting it to the .h file removed the linker warnings.

like image 127
Scoop Avatar answered Nov 10 '22 15:11

Scoop


Do not ignore the warning.

Apple's "Programming With Objective-C" guide, in the "Customizing Existing Classes" section, says:

If the name of a method declared in a category is the same as a method in the original class, or a method in another category on the same class (or even a superclass), the behavior is undefined as to which method implementation is used at runtime.

If it has been working for you, then it's luck.

like image 4
Chris Lundie Avatar answered Nov 10 '22 14:11

Chris Lundie