Avatar ·

Replacing #ifdef in Swift: how to use conditional compilation and flags?

Hello! I'm transitioning from Objective-C to Swift and ran into a problem. In Obj-C, I often used preprocessor directives, for example: ```objectivec #ifdef DEBUG NSLog(@"Debug log"); #else NSLog(@"Release version"); #endif ``` Or for platform checking: ```objectivec #if TARGET_OS_IOS // iOS code #elif TARGET_OS_MAC // macOS code #endif ``` In Swift, I can't find a direct analog of #ifdef. I tried writing something like: ```swift #if DEBUG print("Debug log") #else print("Release version") #endif ``` But Xcode says that `DEBUG` is not defined. I added `-D DEBUG` to Other Swift Flags, but it still doesn't work. How do I properly configure conditional compilation in Swift? Do I need to do something with Build Settings? And can I create my own flags?