【问题标题】:Cast as double?扮演双重角色?
【发布时间】:2011-03-08 13:22:21
【问题描述】:

我怎样才能将某物转身或施放一个替身? CLLocationDegrees 真的是双精度,所以我如何将它转换为双精度,这样我的 if 总是返回双精度,我可以将我的 findAllLocalCountTotal 参数更改为双精度而不是 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];

【问题讨论】:

    标签: objective-c double cllocation


    【解决方案1】:

    只需使用强制转换并将变量声明移到 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;
    }
    

    【讨论】:

      【解决方案2】:

      这个话题对你有帮助吗? cllocationdegrees

      【讨论】:

        猜你喜欢
        • 2020-01-25
        • 1970-01-01
        • 1970-01-01
        • 2023-03-20
        • 1970-01-01
        • 2021-05-17
        • 2019-11-06
        • 2020-12-24
        • 1970-01-01
        相关资源
        最近更新 更多