Search code examples
cocoagarbage-collectionconditional-compilation

Is there conditional statements to exclude code when compiling with GC disabled?


I want my struct to have cocoa objects when GC is set to required:

struct {
  int pod;
#ifdef GC_REQUIRED
  NSString *cocoa;
#endif 
};

Solution

  • When garbage collection is enabled __OBJC_GC__ is defined, so you can check like this:

    struct {
      int pod;
    #ifdef __OBJC_GC__
      NSString *cocoa;
    #endif 
    };