0

In Xcode 6, I found there are 2 settings:

  • Apple LLVM 6.0 - Language > Prefix Header
  • Apple LLVM 6.0 - Preprocessing > Preprocessor Macros Not Used in Precompiled Headers

I know the 1st one is used to link up .pch (which in Xcode 5 era, New Project from template will create 1 default .pch for us), and ask the compiler to read the .pch before compiling the codes.

So my question is, what is the use of 2nd one?

Raptor
  • 53,206
  • 45
  • 230
  • 366

3 Answers3

1

You can define macros here that are available to the pre-processor at compile time

Add something like DEBUG=1 in the settings for the debug compile, then you can use this in your code for example to have a conditional compile:

#ifdef DEBUG
...
#endif

EDIT:
The first is a link to a PCH file. You can do all sorts of definitions there. This will be compiled into the app and executed at runtime.
The second is a place to easily add macros for different compile settings. The macros will alter the code at compile time, for example to add debug code that should not be compiled into the store version or switch server paths or similar. You can also use it if you have 2 different compile targets for 2 different apps (like one iPhone & one iPad version) to add version specific assets or code.

dogsgod
  • 6,267
  • 6
  • 25
  • 53
  • I know. So what is the difference between 2 settings ? – Raptor Nov 24 '14 at 09:01
  • 1
    The first is a link to a file. You can do all sorts of definitions there. This will be executed at runtime. The second is a place to easily add macros for different compile settings. It's valid at compile time only. – dogsgod Nov 24 '14 at 09:06
  • 1
    Neither of the 2 options has a direct connection to the command line. The PCH will be compiled into the app and will be executed at runtime, while the macros will alter the code at compile time, for example to add debug code that should not be compiled into the store version or switch server paths or similar. You can also use it if you have 2 different compile targets for 2 different apps (like one iPhone & one iPad version) to add version specific assets or code. – dogsgod Nov 24 '14 at 09:13
  • Understand. Suggest to update your answer with your valuable comments. – Raptor Nov 24 '14 at 09:37
0

All of the previous comments and answers have eluded to the answer, but possibly not yet clearly answered:

1] Language > Prefix Header: This is where you define your .PCH file, your PreCompiled Prefix Header (we all know what that is, right?)

2] Preprocessing > Preprocessor Macros Not Used in Precompiled Headers: XCode gives you a way to share pre-compiled prefix files, this would be the case if you have multiple targets with similar, but maybe not identical settings... this is more advanced option and covered in detail here; https://developer.apple.com/library/mac/technotes/tn2190/_index.html#//apple_ref/doc/uid/DTS10004305-CH1-TNTAG3

Summary: #1 is for the normal use of PCH, and #2 exists for advanced sharing of PCH + variants in Pre-Compiled definitions

MOK9
  • 375
  • 4
  • 9
-1

Create a PCH file along with project name.

1> projectName.pch

2> Than use this following lines

#import <Availability.h>

#ifndef __IPHONE_3_0
#warning "This project uses features only available in iOS SDK 3.0 and later."
#endif

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

3> Set "Prefix Header" in bundle settings

   ProjectName/ProjectName.pch

Please make sure about the correct location of .pch file which would be inside ProjectName folder.

chandan
  • 2,453
  • 23
  • 31
  • This does not answer the `Preprocessor Macros Not Used in Precompiled Headers` settings – Raptor Nov 24 '14 at 09:36
  • ok but You can define your macro inside this .pch file and can use anywhere. If not please share which Preprocessor Macros you want to use – chandan Nov 24 '14 at 09:59