我收到Xcode 3.2.5静态分析仪的警告,我不太明白,警告是:
警告:消息的接收者 'horizontalAccuracy'是零和 返回type的值 'CLLocationAccuracy'将是 垃圾 如果([lastGoodLocation horizontalAccuracy]< = 希望之处{/ p>
代码编译并运行良好,但我只是好奇发生了什么以及如何解决它。
@property (nonatomic, retain) CLLocation *lastGoodLocation;
@synthesize lastGoodLocation;
// CHECK FOR BEST LOCATION
if(lastGoodLocation == nil || [newLocation horizontalAccuracy] < [lastGoodLocation horizontalAccuracy]) {
NSLog(@"NEWBEST: %0.0fm (%@)", [newLocation horizontalAccuracy], [newLocation timestamp]);
[self setLastGoodLocation:newLocation];
// DESIRED ACCURACY & GEOCODE
if([lastGoodLocation horizontalAccuracy] <= DESIREDACCURACY) {
newLocation可以返回为nil,此代码位于:
locationManager:didUpdateToLocation:fromLocation:
答案 0 :(得分:5)
当if
为零(lastGoodLocation
条件的左侧)时,您可以进入外部||
,并且在if
区块内,您是在可能的nil引用上调用[lastGoodLocation horizontalAccuracy]
。将内部if
更改为
// DESIRED ACCURACY & GEOCODE
if (lastGoodLocation != nil && ([lastGoodLocation horizontalAccuracy] <= DESIREDACCURACY))
可能#setLastGoodLocation
实际上设置了lastGoodLocation
,但分析师可能没有发现它。
修改强>
developer.apple.com处的文档表明虽然oldLocation可能是nil(在第一次修复时),newLocation可能不应该 - 如果位置不起作用,我认为你会收到{{1}而不是。