gpt4 book ai didi

ios - 如何检查宏内的条件?

转载 作者:行者123 更新时间:2023-11-28 21:33:54 25 4
gpt4 key购买 nike

我定义了这样一个宏,

#define SELECTED_SITE_ID (SITE_MANAGER.selectedSite.siteCollectionIdentifier)

它返回存储在用户默认值中的 double 值。

在代码中,SELECTED_SITE_ID 宏被用于 1000 多个这样的地方,

int a = SELECTED_SITE_ID;
NSArray *array = [someClassObject objectAtIndex:a-1];

当我的应用第一次运行时,SELECTED_SITE_ID 宏返回 0.0,它被分配给 int a; 所以 a 将是0

在数组中,我将 a-1 写入 0-1,这会导致崩溃问题。

我现在不知道什么是快速解决这个问题的方法,因为它写在大约。 1000 个位置?

我怎么想的?

I guess inside macro itself? If I would able to check, what's the value coming? if it's 0 then I will explicitly return 1.

如有任何帮助,我们将不胜感激。

最佳答案

这很简单,

#define SELECTED_SITE_ID ((SITE_MANAGER.selectedSite.siteCollectionIdentifier <= 0.0) ? 1 : SITE_MANAGER.selectedSite.siteCollectionIdentifier)

关于ios - 如何检查宏内的条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34672732/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com