Conditional Compiling based on Frameworks

Discussion in 'Mac Programming' started by BadWolf13, Nov 9, 2010.

  1. macrumors 6502

    Joined:
    Dec 17, 2009
    #1
    I'm creating a new class, and it's possible that it'll be used in different situations, so I'm thinking of using conditional compiling on certain methods and instance declarations. Can this be done, or should I just make different classes for different frameworks?
     
  2. macrumors regular

    Joined:
    Mar 5, 2004
    #2
    It's impossible to answer this question without more details.
     
  3. thread starter macrumors 6502

    Joined:
    Dec 17, 2009
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    If you Get Info a target or project, you can define a preprocessor macro under the Build tab. Then you can check for that in the code. So say you define MY_FEATURE, then in code you can use
    Code:
    #ifdef MY_FEATURE
    - (void)myMethod;
    #endif
    Or you can define it elsewhere, such as a .pch or .h file:
     
  5. thread starter macrumors 6502

    Joined:
    Dec 17, 2009
    #5
    Ok, I did hear about the ability to define a macro in the project settings. However, I was looking for something a bit more, automatic. One application that comes to mind first is core-data specific methods and instances. Unfortunately, the cocoa.h file includes coredata.h, so I can't use the definitions in the core data headers. Is there a way around this, or am I SOL on this one?
     
  6. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    Cocoa.framework is just a convenience framework, you don't need to use it. You can link to AppKit, Foundation, and CoreData directly, turning them on and off for any given target.

    Why not just put your CoreData methods in a separate file as a category on your class. Then you can disable compiling that file altogether for the target that doesn't use CoreData. No need to mess with macros.
     
  7. thread starter macrumors 6502

    Joined:
    Dec 17, 2009
    #7
    Hmm, I never thought of using a category. Thanks.
     

Share This Page