开发者

Cast as double?

How can I turn or maybe cast something to a double? CLLocationDegrees is really a 开发者_StackOverflow中文版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?

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:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜