2

I'm adding some swift classes to Objective-C project. The problem is that code under #ifdef in Objective-C classes is not visible in Swift classes. I've defined some static properties to reflect #defines but it is very big overhead to go over whole project and to do that manually. Is there any easier and correct way to do that?

Note: the question is not about how to do in swift... This is about how to handle already existent defines in objective-c to make them visible in swift.

Misha
  • 5,260
  • 6
  • 35
  • 63
  • 1
    http://stackoverflow.com/questions/24003291/ifdef-replacement-in-swift-language go through the above link , it might be helpful – Abi Mar 23 '16 at 10:07

2 Answers2

1

Instead of using #defines why don't you define a class containing const's, then you can switch between object references for different compiles with few lines.

SPlatten
  • 5,334
  • 11
  • 57
  • 128
  • I have already Objective-C project like this. Now I need to find out the easiest way to allow Swift classes to see code under #ifdefs – Misha Mar 23 '16 at 11:25
  • See: http://stackoverflow.com/questions/24003291/ifdef-replacement-in-swift-language – SPlatten Mar 23 '16 at 14:31
0

There has been a new build settings introduced with Xcode 8: Active Compilation Conditions

New setting: SWIFT_ACTIVE_COMPILATION_CONDITIONS

“Active Compilation Conditions” is a new build setting for passing conditional compilation flags to the Swift compiler.

Previously, we had to declare your conditional compilation flags under OTHER_SWIFT_FLAGS, remembering to prepend “-D” to the setting. For example, to conditionally compile with a MYFLAG value:

#if MYFLAG
// do stuff
#endif

The value to add to the setting -DMYFLAG

Now we only need to pass the value MYFLAG to the new setting. Time to move all those conditional compilation values!

Please refer to my answer on another SO post: #ifdef replacement in the Swift language

Community
  • 1
  • 1
DShah
  • 9,768
  • 11
  • 71
  • 127