Conditional Compiling based on Frameworks

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

  1. macrumors 6502

    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

    It's impossible to answer this question without more details.
  3. macrumors 6502

    Which details?
  4. Moderator emeritus


    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
    #ifdef MY_FEATURE
    - (void)myMethod;
    Or you can define it elsewhere, such as a .pch or .h file:
  5. macrumors 6502

    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


    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. macrumors 6502

    Hmm, I never thought of using a category. Thanks.

Share This Page