View Full Version : Conditional Compiling based on Frameworks
Nov 9, 2010, 06:34 PM
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?
Nov 10, 2010, 11:20 AM
It's impossible to answer this question without more details.
Nov 10, 2010, 06:44 PM
Nov 10, 2010, 08:49 PM
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
Or you can define it elsewhere, such as a .pch or .h file:
Nov 10, 2010, 09:50 PM
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?
Nov 10, 2010, 10:02 PM
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.
Nov 10, 2010, 10:35 PM
Hmm, I never thought of using a category. Thanks.