我面临的问题是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。即使我在xcode中控制台记录,它也会显示一个来自RN的数字。
任何解决方案来避免这种情况,但是应用程序也会因此崩溃。
感谢基金会集合(包括NSDictionary
)将数字存储为NSNumber
对象。这个错误告诉你它期望一个unsigned long long,所以你应该使用unsignedLongLongValue
从NSDictionary
中的NSNumber
中提取该值:
NSDecimalNumber *amount_total = [NSDecimalNumber decimalNumberWithMantissa:[indic[@"amount"] unsignedLongLongValue] exponent:-2 isNegative:NO];
参见大多数集合是对象,而数字是由NSNumber类的实例表示的。