在调试模式下运行项目时,Xcode 中未设置 DEBUG 宏

Var*_*pta 5 xcode ios react-native react-native-ios

我创建了一个新的 React-Native 项目,其中包含一个 Android 项目和一个 iOS 项目。我使用的是 Swift,因此我将AppDelegate.mAppDelegate.h文件替换为AppDelegate.swift. 我在 swift 文件中使用DEBUG这样的宏,但即使在调试模式下它也始终设置为 false,因此我无法使用它。

    #if DEBUG
      let jsCodeLocation = RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index", fallbackResource:nil)
    #else
      let jsCodeLocation = Bundle.main.url(forResource: "main", withExtension: "jsbundle")
    #endif
Run Code Online (Sandbox Code Playgroud)

debug我在 Xcode上搜索Build Settings,发现下面的内容似乎设置正确。

在此输入图像描述

如何确保DEBUG在运行调试模式时设置宏,而不是在其他情况下设置宏。谢谢。

Ind*_*ore 7

    \n
  1. 打开您的项目构建设置并搜索Swift Compiler \xe2\x80\x93 Custom Flags
  2. \n
  3. 并在此下转到Other Swift Flags并添加-DDEBUG到“调试”部分
  4. \n
\n\n

让我知道这是否有效,我在我的库中使用了这种方法很久以前就

\n

  • 这对我有用,但我想知道问题的原因。我有另一个项目在没有这些配置的情况下工作, (3认同)