【发布时间】:2012-05-24 19:16:52
【问题描述】:
对于对象,如果对象无效,我可以编写一个访问器以返回 nil:
- (Weather *)howsTheWeather
{
if (![WeatherNetwork isAvailable]) {
return nil;
}
Weather *weatherNow = [WeatherNetwork getWeather];
return weatherNow;
}
我想用CLLocationCoordinate2D 和struct 来保存纬度和经度。我试过这个:
- (CLLocationCoordinate2D)coordinate
{
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(self.latitude, self.longitude);
if (!CLLocationCoordinate2DIsValid(coord)) {
return nil;
}
return coord;
}
但是编译器会报错“返回 'void *' from a function with in compatible result type 'CLLocationCoordinate2D'”
处理这种情况的最佳方法是什么?我正在考虑编写一个单独的方法-(BOOL)isLocationValid:(CLLocationCoordinate2D)coordinate。有没有更好的方法来解决这个问题?
【问题讨论】:
标签: iphone objective-c cocoa-touch struct