gpt4 book ai didi

ios - 函数返回值错误(可能是错误的字符串 "type"?)

转载 作者:行者123 更新时间:2023-11-28 18:43:38 25 4
gpt4 key购买 nike

我有一个函数应该返回一个 int 值。

- (int)function:(NSString *)input
{
if (input == @"test1")
{
return 0;
}
if (input == @"test2")
{
return 1;
}
if (input == @"test3")
{
return 2;
}
else
{
return 3;
}
}

这里我调用函数:

[self function:self.detailItem.type]

调试器显示 input __NSCFString * 0x6b9a0b0 并返回任何 29938idontknow 值。

如果我调用 [self function:@"test1"] 一切正常。

detailItemTV 的类型,它是 NSManagedObject,其属性 type 定义为 字符串string 类型应该有问题吗?

谢谢!

最佳答案

你应该像这样比较 NSString :

if ([input isEqualToString:@"test1"])
{
// Some code here
}

关于ios - 函数返回值错误(可能是错误的字符串 "type"?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8049373/

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