简体   繁体   English

演员加倍?

[英]Cast as double?

How can I turn or maybe cast something to a double? 我该如何转身或者将某些东西变成双人? CLLocationDegrees is really a double so how do I cast it as double so my if always returns doubles and I can change my findAllLocalCountTotal params to double instead of CLLocationDegrees? CLLocationDegrees实际上是一个双倍,所以我如何将其转换为double,所以我总是返回双精度,我可以将我的findAllLocalCountTotal参数更改为double而不是CLLocationDegrees?

if(self.lastKnownLocation == nil ){
    double lat = [CLController sharedInstance].latitude;
    double lng = [CLController sharedInstance].longitude;

}else{
    CLLocationDegrees lat = self.lastKnownLocation.coordinate.latitude;
    CLLocationDegrees lng = self.lastKnownLocation.coordinate.longitude;
}

NSNumber *tempInt = self.lastPostsGrabbedCounter;



//Make call to get data with lat lng
self.webServiceAllCount = [Post findAllLocalCountTotal:(CLLocationDegrees)lat withLong:(CLLocationDegrees)lng];

Just use a cast and also move the variable declaration outside of the if - the if & else branches are distinct scopes and introduced their own variables: 只需使用强制转换并将变量声明移到if之外 - ifelse分支是不同的范围并引入它们自己的变量:

double lat, lng;
if(self.lastKnownLocation == nil)
{
   lat = [CLController sharedInstance].latitude;
   lng = [CLController sharedInstance].longitude;
}
else
{
   lat = (double)self.lastKnownLocation.coordinate.latitude;
   lng = (double)self.lastKnownLocation.coordinate.longitude;
}

This topic can help you ? 这个话题可以帮到你吗? cllocationdegrees cllocationdegrees

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM