如何在#ifdef 中编写if 条件。用于分期。在 Objective-C 中

发布于 2024-12-01 11:21:23 字数 355 浏览 0 评论 0原文

我需要在此调用中添加一个条件暂存..

如何在这种情况下执行此操作。

  #ifdef MYAPP_PRODUCTION
        buildMode = @"Production";
    #else

    #ifdef MYAPP_RELEASE
        buildMode = @"Release";
    #else MYAPP_DEBUG
       buildMode = @"Debug";
    #endif
    #endif

另一个是 MyApp_Staging 需要在此 if 条件中包含如何做到这一点?

I need to add one more condition inside this call Staging..

how to do it in this condition.

  #ifdef MYAPP_PRODUCTION
        buildMode = @"Production";
    #else

    #ifdef MYAPP_RELEASE
        buildMode = @"Release";
    #else MYAPP_DEBUG
       buildMode = @"Debug";
    #endif
    #endif

another is MyApp_Staging need to include in this if condition how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

冷心人i 2024-12-08 11:21:23

您可以执行类似的操作来包含所有不同的选项,包括新的暂存模式,并使整个语句更清晰:

#ifdef MYAPP_PRODUCTION
    buildMode = @"Production";
#elif MYAPP_RELEASE
    buildMode = @"Release";
#elif MYAPP_DEBUG
    buildMode = @"Debug";
#elif MYAPP_STAGING
    buildMode = @"Staging";
#endif

You could do something like this to contain all the different options including the new Staging Mode and make the whole statement cleaner:

#ifdef MYAPP_PRODUCTION
    buildMode = @"Production";
#elif MYAPP_RELEASE
    buildMode = @"Release";
#elif MYAPP_DEBUG
    buildMode = @"Debug";
#elif MYAPP_STAGING
    buildMode = @"Staging";
#endif
等风来 2024-12-08 11:21:23

你的问题不是很清楚......如果你想在 #ifdef 中使用多个条件,这里有一个解决方案:

#if defined(MYAPP_RELEASE) && defined(MyApp_Staging)
    // ...
#else
    // ...
#endif

Your question is not very clear... If you want multiple conditions in a #ifdef, here is a solution:

#if defined(MYAPP_RELEASE) && defined(MyApp_Staging)
    // ...
#else
    // ...
#endif
你在看孤独的风景 2024-12-08 11:21:23

在 Swift 和 Xcode 7 中,语法发生了变化:

#if DEBUG || RELEASE
    let URL = "https://www.example.com/beta"
#elseif APPSTORE
    let URL = "https://www.example.com/prod"
#endif

In Swift and Xcode 7, the syntax has changed:

#if DEBUG || RELEASE
    let URL = "https://www.example.com/beta"
#elseif APPSTORE
    let URL = "https://www.example.com/prod"
#endif
晨敛清荷 2024-12-08 11:21:23

如果您想用 2 个构建目标来否定条件,请像这样使用。

#if !(TOWNTALK || EPISD)

In case if you want to negate the condition with 2 build targets, use like this.

#if !(TOWNTALK || EPISD)

十二 2024-12-08 11:21:23

这又如何呢?

#if defined(MYAPP_PRODUCTION)
  buildMode = @"Production";
#elif defined(MYAPP_RELEASE)
  buildMode = @"Release";
#elif defined(MYAPP_DEBUG)
  buildMode = @"Debug";
//#elif defined(MYAPP_STAGING)
#else
  buildMode = @"Staging";  
#endif  

What about this?

#if defined(MYAPP_PRODUCTION)
  buildMode = @"Production";
#elif defined(MYAPP_RELEASE)
  buildMode = @"Release";
#elif defined(MYAPP_DEBUG)
  buildMode = @"Debug";
//#elif defined(MYAPP_STAGING)
#else
  buildMode = @"Staging";  
#endif  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文