简体   繁体   English

JSONModel:MKAnnotation和CLLocationCoordinate2D

[英]JSONModel: MKAnnotation & CLLocationCoordinate2D

I am using JSONModel ( https://github.com/icanzilb/JSONModel ) inorder to handle my JSON data. 我正在使用JSONModel( https://github.com/icanzilb/JSONModel )来处理我的JSON数据。 I just have problem related to adding a CLLocationCoordinate2D property in my JSONModel Subclass, in order to respond to the MKAnnotation protocol. 我只是遇到与在我的JSONModel子类中添加CLLocationCoordinate2D属性相关的问题,以便响应MKAnnotation协议。 Since the incoming JSON dosen't contain a coordinate field, but seperated fields with Lat & Lon, and since CLLocationCoordinate2D isn't an object, JSONModel want let me ignore protocol. 由于传入的JSON不包含坐标字段,而是用Lat&Lon分隔字段,并且由于CLLocationCoordinate2D不是对象,因此JSONModel要让我忽略协议。

This is my code: 这是我的代码:

@protocol Store @end
@interface Store : JSONModel <MKAnnotation>

@property (nonatomic, copy, readonly) NSString *Name;
@property (nonatomic, copy, readonly) NSNumber *Longitude;
@property (nonatomic, copy, readonly) NSNumber *Latitude;

//Can be ignored since it is not an object type. 
@property (nonatomic, assign) CLLocationCoordinate2D <Ignore> coordinate;
@end

How can I ignore the coordinate property? 如何忽略坐标属性?

Just check the documentation 只需检查文档

http://cocoadocs.org/docsets/JSONModel/0.11.0/Classes/JSONModel.html#//api/name/propertyIsIgnored: http://cocoadocs.org/docsets/JSONModel/0.11.0/Classes/JSONModel.html#//api/name/propertyIsIgnored:

Here's the code for your model: 这是您的模型的代码:

+ (BOOL)propertyIsIgnored:(NSString *)propertyName
{
  if ([propertyName isEqualToString:@"coordinate"]) {
    return YES;
  }
  return NO;
}

Edit: Although what I would do if I were you is to have a custom transformer for the coordinate property that would read the 2 incoming json keys and produce a location struct for you automatically. 编辑:虽然如果我是我将要做的是为座标属性定义一个自定义转换器,它将读取2个传入的json键并自动为您生成一个位置结构。 Just an idea... 只是个主意...

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

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