gpt4 book ai didi

ios - NSString stringByReplacingOccurrencesOfString 失败

转载 作者:行者123 更新时间:2023-11-28 22:57:03 24 4
gpt4 key购买 nike

我正在尝试使用 stringByReplacingOccurrencesOfString 将一个字符串替换为另一个字符串,但由于某种原因,它给了我这个错误:

-[__NSCFNumber length]: unrecognized selector sent to instance 0x6e49ef0 2012-05-14 16:30:49.741 coop[78129:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0x6e49ef0'

NSString *_currentGroup;
NSString *location = [current objectForKey:@"location"];
if(_currentGroup != nil)
{
NSLog(@"_currentGroup: %@", _currentGroup);
// OUTPUT: _currentGroup: 92

location = [location stringByReplacingOccurrencesOfString:@"%group_id%" withString:_currentGroup];
}

当我尝试以下操作时,它就起作用了

location = [location stringByReplacingOccurrencesOfString:@"%group_id%" withString:@"anyOtherString"];

我还遗漏了什么吗?

最佳答案

您的“NSString”实际上是一个NSNumber。这就是错误告诉您的内容。

关于ios - NSString stringByReplacingOccurrencesOfString 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10579901/

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