我具备拥有的实例变量的自定义类的坐标:处理空结构在Objective-C(定制类坐标)
CLLocationCoordinate2D eventLocation;
@property(nonatomic) CLLocationCoordinate2D eventLocation;
我解析一个具有可选字段的XML文件那可能会也可能不会。 如果是我设置它像这样:
CLLocationCoordinate2D location;
NSArray *coordinateArray = [paramValue componentsSeparatedByString:@","];
if ([coordinateArray count] >= 2) {
location.latitude = [[coordinateArray objectAtIndex:0] doubleValue];
location.longitude = [[coordinateArray objectAtIndex:1] doubleValue];
} else {
NSLog(@"Coordinate problem");
}
info.eventLocation = location;
我做的这基本上是一个地图
annotation.coordinate = alert.info.eventLocation;
我知道我需要做一些检查这里以确保该上添加注解存在但我不允许做if (info.eventLocation == nil)
甚至if (info.eventLocation.latitude == nil)
这似乎是一个非常基本的问题,但我做了一些搜索,没有人能够真正提供一个很好的答案/想法。我的架构完全关闭了吗?
当我加入这个我我的自定义对象的.h文件中遇到错误: 初始值设定元素不是常数 (近初始化为“EmptyLocationCoordinate.latitude”) 初始值设定元素不是常数 ('EmptyLocationCoordinate.longitude'的初始化附近) – aleclerc 2009-11-02 20:10:37
实际上, alert.info.eventLocation = EmptyLocationCoordinate 仍然会给出“无效操作数为二进制!=”错误 – aleclerc 2009-11-02 20:55:36
啊,也许你需要#define EmptyLocation。 – 2009-11-02 21:22:18