views:

729

answers:

2

Just as background, there are no compile-time errors or warnings in the subject project "Project".

There are numerous occurrences of using the same instance variable name in two (or more classes). In the following, I'll use the variable name "index" as an example. It appears as an instance variable in class1 and class2. The variable has different but similar meanings in both classes, hence the use of the common term.

I define index in the header file for both class1 and class2, for example:

@interface class1 : NSObject { int index; } ...

Repeat for class2.

When I build the project, Xcode reports:

Duplicate symbol _index in /Project/build/Project.build/Debug-iphonesimulator/Project.build/Objects-normal/i386/class1.o and /Project/build/Project.build/Debug-iphonesimulator/Project.build/Objects-normal/i386/class2.o

Changing the occurrences of "index" to "indexnotverycommon", reports the same error with the new name.

Changing the occurrences to "index1" and "index2" respectively gets rid of the error. Xcode then reports the next duplicate it finds during linking, and so on, and so on.

I can continue the renaming process although I'd rather not, as I'm concerned that there is a more pathological underlying issue.

Any advice or question is appreciated.

+2  A: 

index is a also a C function and thus a very unfortunate name in Objective-C. This article describes why it's not a good idea to use index as a name.

I'm not sure why you get duplicate symbols though.

diciu
A: 

I figured it out using the Xcode find-in-project feature. Thanks for the advice about index.

McPragma
Was this because you accidentally had an #import of a .m file where you meant the .h?
cdespinosa