Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3335024
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:58:14+00:00 2026-05-17T23:58:14+00:00

I have an XCode project with 2 targets (both are iPhone apps sharing 95%

  • 0

I have an XCode project with 2 targets (both are iPhone apps sharing 95% of the same code).
However, one module isn’t “shareable”; the implementations are too different.

My solution (that is not working) was to add 2 subdirectories to my Classes/ folder in my project directory – one for each target. In each directory, I’ve placed a view controller class, called ExampleSentencesViewController. Of course, each file is compiled as part of only one of the targets – I’m looking for an “automatic switching” of which implementation to use based on the target.

Inside each target’s settings, I added each directory to the “Header Search Paths” setting (each path for each target).

Oddly, it only compiles for the original target. The target I added later won’t compile, claiming that I’ve included the same header twice (there ARE two files, to be fair). How do I get XCode to forget about the original header??

I’ve tried deleting the .h files out of my project, but that does not seem to help.

Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:58:14+00:00Added an answer on May 17, 2026 at 11:58 pm

    fully qualify the header paths in the separate implementation files, based on one of your defined search directories:

    #include <MONProject/Source/ExampleSentencesViewController.h>

    vs

    #include <MONSecondProject/Source/ExampleSentencesViewController.h>

    update based on clarification:

    ideally, you’d create a static library for the shared code.

    for a simple case… you could take the direct approach by populating a header in your project’s root, named ExampleSentencesViewController.h, and populating it like so:

    /* you must define either MON_BUILD_MON_FIRST_PROJECT or MON_BUILD_MON_SECOND_PROJECT at the target level */
    
    #if (defined(MON_BUILD_MON_FIRST_PROJECT) && defined(MON_BUILD_MON_SECOND_PROJECT))
    #error invalid configuration: you cannot specify both projects to be compiled
    #elif defined(MON_BUILD_MON_FIRST_PROJECT)
    /* some fully qualified path: */
    #include <MONFirstProject/ExampleSentencesViewController.h>
    #elif defined(MON_BUILD_MON_SECOND_PROJECT)
    /* some other fully qualified path: */
    #include <MONSecondProject/ExampleSentencesViewController.h>
    #else
    #error uh... which project are you trying to build?
    #endif
    

    or you could just use these defines to conditionally enable/disable the interface and implementation of the classes with duplicate names (and then just include them both in the project’s declaration of:

    /* MONFirstProject/ExampleSentencesViewController.h> */
    
    #if defined(MON_BUILD_MON_FIRST_PROJECT)
    @interface ExampleSentencesViewController : NSViewController
    /* ... */
    @end
    #endif
    

    …but this will require to include both headers in your distribution (if applicable).

    some of the finer details of inclusion can vary based on how you’ve declared your search paths (e.g., are they recursive or not?) and whether you use copy headers build phases in your xcodeproj. maintaining both projects which share code can become messy if you’ve been too relaxed in your include directives, discovery options, preprocessor declarations (conditional compilation/visibility) and/or build configurations so… that’s why i recommend a library for the shared bits. this conditional stuff (in the two previous examples) is error prone and doesn’t evolve or scale well. doing this is also a good way to confuse other tools in the development toolkit.

    in fact, i prefer this over the preprocessor (assuming you’re able to distribute both classes):

    - (UIViewController *)newViewControllerForMyAwesomeView {
        if (IsAppMONFirstProject) {
            return [[MONFirstProjectViewController alloc] init...];
        }
        else if (IsAppMONSecondProject) {
            return [[MONSecondProjectViewController alloc] init...];
        }
        else {
            assert(0 && "definitely break up your code, now that it is referenced by 3 or more projects");
            return 0;
        }
    }
    

    if you’re merely maintaining two versions of the same title, then practices will be much different.

    anyways… this should be enough ideas to solve your problem – you just have to determine the lesser evil.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two cocoa-touch apps in one Xcode project. Xcode gives me iPhone/iPad related
I tried to create multiple iPhone apps using same XCode project and that worked
I am new to using multiple targets in a xcode project and have hit
I have an Xcode project with the following group structure: ProjectName/ Classes/ class1.h class1.m
I have an XCode project where when I click on Project->Edit Project Settings I
I have this run as a Shell Script target in my Xcode project #
Have you guys had any experiences (positive or negative) by placing your source code/solution
I am trying to set up Xcode for a project which contains multiple executables
I have a project that I've just finished painstakingly rebuilding because duplicating a target
Have just started using Google Chrome , and noticed in parts of our site,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.