I would like to create a define based on the status of iTunes File Sharing boolean status on the Info.plist file. So, I have created this:
#define itunesFileSharingEnabled [[[NSBundle mainBundle] \
objectForInfoDictionaryKey:@"UIFileSharingEnabled"] boolValue]
#if itunesFileSharingEnabled
#define something
#endif
but the if fails with the error invalid token at start of preprocessor expression.
if I substitute #define itunesFileSharingEnabled with
#define itunesFileSharingEnabled YES
than the if compiles perfectly. So the error is on the previous line. Xcode is not liking the #define line.
What I want is to define some directive to be true if itunes file sharing is YES and NO if it is not.
How do I declare that?
thanks.
edit:
the problem is that I cannot use regular if to check for iTunes file sharing at run time because I want to make the compiler fail using #error or #warning directive…
for example, later in my code I want to use this
#if iTunesFileSharingEnabled
#error TURN OFF FILE SHARING
#endif
I want the compiler to fail if file sharing is turned on.
Preprocessor directives are evaluated at compile time.
after the first run of the preprocessor
becomes
During the second run the preprocess tries to validate
[[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIFileSharingEnabled"] boolValue]. Which won’t work because this can’t be evaluated at compile time. This is a statement that can only be evaluated at run-time.I don’t know if the stuff you want to do is possible at all. (I don’t know much about the preprocessor).
I guess you know already that you can do those checks at runtime
Another option would be to enforce a manually entered precompiler macro
This goes into your code, somewhere were it is only called once. Probably in the init of your library:
This has to be entered in the
Build SettingsasPreprocessor Macro:If
HAS_ITUNES_FILESHARING=1is not declared in the preprocessor macro section, but File Sharing is active the code will throw an exception.If
HAS_ITUNES_FILESHARING=1is declared, but File Sharing is not active, the code will raise an exception too.This way you can always tell that the preprocessor macro matches the configuration. If you only call this once (in
+(void)initializethere should be no performance impact at all.