objective-c – 使用不兼容类型’id’的表达式初始化’double’

前端之家收集整理的这篇文章主要介绍了objective-c – 使用不兼容类型’id’的表达式初始化’double’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图使用以下代码为double赋值:
double distanceFormat = [self.runsArray[indexPath.row] valueForKey:@"runDistance"];

但我不断收到以下错误

Initialising 'double' with an expression of incompatible type 'id'

但是,我知道价值是双倍的!有没有办法做到这一点?

解决方法

你可以尝试:
double distanceFormat = [[self.runsArray[indexPath.row] valueForKey:@"runDistance"] doubleValue];

如果你确定它是双倍的,我认为它会起作用.

原文链接:https://www.f2er.com/c/119959.html

猜你在找的C&C++相关文章