目标 C 中的设置变量不正确

improper setting variable in objectiveC

我面临 xcode 向我显示警告的问题:Incompatible pointer to integer conversion sending 'id _Nullable' to parameter of type 'unsigned long long'

该行是:

NSDecimalNumber *amount_total = [NSDecimalNumber decimalNumberWithMantissa:indic[@"amount"] exponent:-2 isNegative:NO];

它抱怨 indic[@"amount"] 这是来自 React-Native 的 amount 值。即使我在 xcode 控制台中登录它,它也会显示一个来自 RN 的数字。

任何避免这种情况的解决方案,但是应用程序也会因此崩溃。

谢谢

基金会 collections(包括 NSDictionary)将号码存储为 NSNumber objects。该错误通知您它需要一个 unsigned long long,因此您应该使用 unsignedLongLongValueNSDictionary:

中的 NSNumber 中提取该值
NSDecimalNumber *amount_total = [NSDecimalNumber decimalNumberWithMantissa:[indic[@"amount"] unsignedLongLongValue] exponent:-2 isNegative:NO];

参见Most Collections Are Objects and Numbers Are Represented by Instances of the NSNumber Class