0
我在将CCLocationManager方法转换为块时遇到问题。 我CLLocationManager方法是这样的:如何将CLLocationManager方法转换为iOS中的块目标c
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
}
else{NSLog(@"current location is nil");};
}
我想这种方法转换成块,但在试图这样做有困难。一种新的客观的C和IOS开发。
我在做什么是这样的:
double (^getSpeed)(*CLLocation, *CLLocation) = ^(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocation *currentLocation = newLocation;
mSpeed = currentLocation.speed;
}
else{NSLog(@"current location is nil");};
return mSpeed;
};
,但它给了我一个错误说,它预计在块的第一行的表达式。这是什么意思? 任何帮助,将不胜感激。
我同意但它不能返回任何东西。基本上我试图在另一个函数中写一个块,它会返回给我一个速度 – Nik391
如果“didUpdateLocations”委托方法被调用“updateCurrentLocation”,则必须返回该位置。检查代表是否正在呼叫。在块中,它可以计算出你想要的速度。 – Vishnuvardhan
感谢您的澄清 – Nik391