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 9232643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:21:46+00:00 2026-06-18T06:21:46+00:00

I would like to create a define based on the status of iTunes File

  • 0

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.

  • 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-06-18T06:21:47+00:00Added an answer on June 18, 2026 at 6:21 am

    Preprocessor directives are evaluated at compile time.

    after the first run of the preprocessor

    #define itunesFileSharingEnabled [[[NSBundle mainBundle] \
    objectForInfoDictionaryKey:@"UIFileSharingEnabled"] boolValue]
    
    #if itunesFileSharingEnabled
    #define something
    #endif
    

    becomes

    #if [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIFileSharingEnabled"] boolValue]
    #define something
    #endif
    

    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

    if ([[[NSBundle mainBundle] \
    objectForInfoDictionaryKey:@"UIFileSharingEnabled"] boolValue]) {
        [self foo];
    } 
    else {
        [self bar];
    }
    

    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:

    #if HAS_ITUNES_FILESHARING
        if (![[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIFileSharingEnabled"] boolValue]) {
            [NSException raise:@"MBFileSharingNotActiveButDeclaredException" format:@"File sharing is not active but \"HAS_ITUNES_FILESHARING\" is set to 1"];
        }
    #else
        if ([[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIFileSharingEnabled"] boolValue]) {
            [NSException raise:@"MBFileSharingActiveButNotDeclaredException" format:@"File sharing is active but you did not declare it as preprocessor macro. Please set \"HAS_ITUNES_FILESHARING\" to 1"];
        }
    #endif
    

    This has to be entered in the Build Settings as Preprocessor Macro:

    HAS_ITUNES_FILESHARING=1
    

    If HAS_ITUNES_FILESHARING=1 is not declared in the preprocessor macro section, but File Sharing is active the code will throw an exception.

    If HAS_ITUNES_FILESHARING=1 is 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)initialize there should be no performance impact at all.

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

Sidebar

Related Questions

i would like create a array of structure which have a dynamic array :
I would like to create this shape using just css. I am pretty sure
I would like to create an object in PHP based on a type defined
I would like to define some properties in my logback.xml config file and saw
I would like to have a class implement operator() several different ways based on
I would like to create a c++ type that mimic the build-in type exactly.
I would like to create a json object to send as a post array,
I would like to create set of strings and below is the only limitation.
I would like to create a class that runs something (a runnable) at regular
I would like to create a virtual host in apache2, but I want it

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.