gpt4 book ai didi

ios - 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因 : '-[NSDecimalNumber length]:

转载 作者:太空宇宙 更新时间:2023-11-03 15:52:21 24 4
gpt4 key购买 nike

使用这些代码行:

PayPalPayment *payment = [[PayPalPayment alloc] init];
NSLog(@"Price %@",[self.product objectForKey:@"Price"]);
NSString *string = [self.product objectForKey:@"Price"];
payment.amount = [[NSDecimalNumber alloc] initWithString:string];

我的应用因以下日志而崩溃:

[NSDecimalNumber length]: unrecognized selector sent to instance

NSLog 正在返回:

Price 96.67

为什么会崩溃???

最佳答案

我猜你有一个类型问题,很可能是对象在
[self.product objectForKey:@"Price"];
我的猜测是这个对象已经是一个 NSDecimalNumber,当你把它当作一个字符串然后使用它调用 initWithString 方法时,不好的事情发生了

在以下位置设置断点:
payment.amount = [[NSDecimalNumber alloc] initWithString:string];

然后在调试器中输入 po [string class]

这将向您显示存储在 [self.product objectForKey:@"Price"];

的对象类型

关于ios - 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因 : '-[NSDecimalNumber length]:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20644778/

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