0

We have a suite of apps which share a set of common screens. Some screens have use more functionality in some apps than others. For example, in one app our issue screen supports tags, but in the others it doesn't. In one, our regions screen supports workflows, but in the others it doesn't.

We're using core data, and the different apps have different data models; If an entity isn't used by an app's data model, the corresponding class doesn't get built into that app.

The result of this is that some of our controllers contain references to classes that may or may not exist when the controller is used in a particular app. At the moment, we get around this using "magic" #defines in our apps' PCH files; so some code in our Issue controller is wrapped in #ifdef SGB_ISSUES_HAVE_TAGS and some code in our Regions controller is wrapped in #ifdef SGB_REGIONS_ARE_FILTERED_BY_WORKFLOW.

What I'd like is to do this instead by detecting whether a file has been included in the project. So at the top of our Issue controller I'd have something like this:

#if exists_in_project("SGBIssueTag.h")
#import "SGBIssueTag.h"
#endif

and then I could put #ifdef SGB_ISSUES_HAVE_TAGS into SGBIssueTag.h; any app we built that used the issue controller would get the issue tag functionality as soon as we included the IssueTag entity, and we wouldn't have to mess around with the PCH file.

Is anything like this possible?

Simon
  • 25,468
  • 44
  • 152
  • 266

1 Answers1

0

This issue has bitten a lot of people - the issue of header files being "global" to a project.

My suggestion is to try and force errors during compilation. You can add in a PCH or file included there defines for each App - lets say you have app A, B, and C. So during any one build, only one of these is active.

Then, in every .m file (and possibly some .h files), you will conditionally include headers:

...
#if defined(A) || defined(B)
#include "SomeInterfaceFile.h"
#endif
...

Once you start building A, you will get compilation errors in files where the source code refers to some object that is defined in a out-of-scope header file. That code you will also have to wrap in a similar if statement.

This will work perfectly, with the downside that your code gets cluttered with these conditional statements.

David H
  • 40,852
  • 12
  • 92
  • 138
  • Thanks. That's what I'm doing at the moment - "we get around this using "magic" #defines in our apps' PCH files" - I was wondering whether it was possible to do it automatically based on what is part of the Xcode project rather than. – Simon Oct 23 '13 at 15:10