2

I'm trying to regroup several applications I have in the same Xcode project. So I created a new Xcode project and added two targets, and import the source code of my two apps in one of the targets.

The problem is that I have classes with the same name in the two applications. When I compile the first one, no problem. But if I try to compile the second target, I have lots of issues like this :

In file included from /Users/administrateur/Documents/Merged_iPhone_Projects/Target2/Classes/VisitFormViewController.m:18:
In file included from /Users/administrateur/Documents/Merged_iPhone_Projects/Target1/Classes/VisitFormDetailsViewController.h:11:

/Users/administrateur/Documents/Merged_iPhone_Projects/Target1/Classes/RoundedCornersTableViewCell.h:18:61: error: property has a previous declaration
@property (nonatomic, readonly) BkCustomCellBackgroundView *roundedCornersView;
                                                            ^
Target2/Classes/RoundedCornersTableViewCell.h:18:61: note: property declared here
@property (nonatomic, readonly) BkCustomCellBackgroundView *roundedCornersView;

I try to google it and found that setting the "Header Search Paths" to $(SRCROOT)/Target1 (or $(SRCROOT)/Target2), should solve my problem, but this is not working.

Anybody has an other solution?

FYI, I'm using Xcode v.4.4.1

aheze
  • 24,434
  • 8
  • 68
  • 125
Niko
  • 2,543
  • 1
  • 24
  • 29
  • here is another answer, follow this link: http://stackoverflow.com/questions/2596695/controlling-which-project-header-file-xcode-will-include try it and tell me if it works! – Alex Lee Sep 10 '12 at 11:20
  • I tried to set the HEADERMAP_INCLUDES_FLAT_ENTRIES_FOR_TARGET_BEING_BUILT to NO as explained in the link you sent me, but the issue remains. – Niko Sep 11 '12 at 14:16
  • I tried another thing. Setting the USE_HEADERMAP to NO, and add $(SRCROOT)/Target1 (or 2) in the "Header Search Paths" section and this works! My question now, might I be rejected from the Apple Store because of this user-defined setting. – Niko Sep 11 '12 at 14:58

2 Answers2

4

You should arrange the resources for each target by directory and define the target membership in the file inspector.

Also, for each target you can use a "user build setting" that is undocumented:

USE_HEADERMAP = NO

and set in each target "User Header Search Path" variable to the the headers directory location.

For more information and more detailed explanation, please refer to this question and answer in stackoverflow

controlling which project header file Xcode will include

Community
  • 1
  • 1
gmauri21
  • 114
  • 2
  • 3
  • This worked and made it possible for me to have two different classes with the same name in two different targets. But now I can't rename one of the classes using Refactor > Rename without also renaming the other. – Noah Nuebling Jun 02 '21 at 11:58
0

The classes will need different names -- otherwise, there will be a collision at load, and the implementation which you will receive is not specified.

justin
  • 104,054
  • 14
  • 179
  • 226
  • What is most amazing and shows how crappy xcode is, is class collision of classes Xcode creates, like AppDelegate. This is, at least, a 5 years old bug. Xcode is designed with hate and disdain, what is sad. – Duck Apr 05 '15 at 07:48
  • @SpaceDog ObjC class names live in a global namespace. This allows you to look up class interfaces and create instances by name via the runtime, but there are caveats -- loading collisions and complex prefixing being the obvious. – justin Apr 08 '15 at 04:11
  • it makes no sense: I have two classes with the same name but one is assigned to one target and the other to another target. There is no reason for collision, just bad implementation, but this is another synonymous for xcode. – Duck Apr 08 '15 at 18:24
  • You're wrong. Different targets are not compiled together, therefore name collision is impossible at runtime. – pronebird Aug 26 '16 at 09:15
  • @Andy the implementations of these independent like-named classes exist in different images/binaries. for example, your app and a framework or library which is directly or indirectly loaded. in fact, the set of names is able to change as some of these libraries are updated. suppose your app implemented a class named `WKWebView` years ago. now Apple releases `WKWebView` -- as in, the WebKit class. once the updated `WebKit` and your app's classes load, the collision is encountered. additionally, there are many private classes to collide with. – justin Sep 27 '16 at 08:09