Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BadWolf13

macrumors 6502
Original poster
Dec 17, 2009
271
0
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?
 
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:
 
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?
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.