Xcode 4.5 warns of method name conflicts between categories for parent / child classes

I am working on a project that was originally built in Xcode 4.0, and then ported to Xcode 4.2. Now I checked the migration to Xcode 4.5 and I get a ton of warnings as shown 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 did not change.

The project is installed in iOS 4.3 for deployment purposes.

So, the previous developer has a bunch of classes like DAO, which, I believe, were automatically generated from CoreData, and then each of these classes has a category that extends it to implement certain methods. I will give an example ...

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

Then we have a class called HistoryObject that inherits from LisaObject. There is also a category for the HistoryObject called HistroyObject + extras. This category also has a method called "values". In the HistoryObject + extras value method, it calls [supervalues] and then checks some conditions and sets some additional values ​​in the dictionary that are not set in the base class method.

Then we have a class called LessonStatusObject, which inherits from HistoryObject, and also has a category called LessonStatusObject + extras, which has a method called values. This value method also calls [supervalues] and then does some extra work with the returned dictionary.

For each of these β€œvalue” methods, we get a warning at compile time, as shown above, which indicates that the category has a method with a conflicting name.

I have a few questions about this.

First, can this implementation cause any legitimate problems, or are these warnings usually benign? I tried to think about how this implementation can cause ambiguity at runtime, but I do not see how this can happen.

Secondly, is there something I have to do to fix these warnings (and I don’t just want to make them stop appearing, I mean to correct the cause)? Is there any other way we should do this?

Also, why didn't Xcode 4.2 warn about this, but does Xcode 4.5 warn?

Am I misunderstanding something about the categories? I mean, if the "values" method was actually part of every implementation of the class, it would not be a problem to redefine them the way we do, but the compiler seems to complain just because it is a category. Is anything unsafe?

Any advice is greatly appreciated.

EDIT: Just to provide more information ... When we used Xcode 4.2, the Apple LLVM Compiler 3.0 was installed in the project. Now when I open the project in Xcode 4.5, it has a compiler installed in Apple LLVM Compiler 4.1.

+7
source share
3 answers

Do not ignore the warning.

Apple "Programming with Objective-C" in Customizing Existing Classes ":

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

If it works for you, then it is luck.

+4
source

I had the same nasty problem, and it turned out that I accidentally included this .m category file instead of the .h file in one of my VC codes. Fixing this .h file removed linker warnings.

+28
source

I also had this problem, but it was caused by something else. For me, it was that the category was added to the Xcode project twice! I did not find that this was so until I renamed one of the methods and saw in the refactoring preview that he had listed the category file twice.

0
source

All Articles