"Redefenition of 'Category' as a different kind of symbol" and conflict with Objc runtime class names

StackOverflow https://stackoverflow.com/questions/20353408

  •  25-08-2022
  •  | 
  •  

Question

I have got a class in Objective-C:

@interface Category : NSObject
{
// ...
}

All was good and I've used this class with no problems in 3 different projects.

Once I decided to create test target for one project. Then the strange thing occurred: compiler refuses to compile with this error:

Redefenition of 'Category' as a different kind of symbol

it also pointed to runtime.h with

typedef struct objc_category *Category;

Well, it is reasonable.

However, I can not understand why it allowed me to use this class before and what is the difference between original target and test target. I've checked Deploy target, iOS SDK, all macros, header paths, #import <objc/runtime.h> and classes in both targets - these are almost the same.

I don't want to refactor this class's name because of using it in multiples projects, so what can be the reason for such a behavior?

Was it helpful?

Solution

You should refactor the name of this class anyway, to avoid such collisions in the future. And it will be less painful to do it sooner rather than later.

It is probable that you import a file that imports <objc/runtime.h> at some point. As the matter of what the difference is between the test target and the regular target, on Xcode testing works by injecting the symbols onto a bundle. There might be some differences in code stripping and symbols visibility that could explain this kind of error.

No wonder Apple recommends to prefix classes with 2 or 3 letters

OTHER TIPS

Although you should do what @Olotiar says in his answer, there's a quick fix.

Go to your project Build Settings, search for "Enable Modules (C and Objective-C)" and set the value to NO.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top