2

I need to have one property which is not present in JSON but it need to be set when I try to use this Model Object. I think it'd be easier to show you the example...

Here is my sample JSON:

[{
  "name" : "Safari",
  "key" : "safari",
  "app_url_scheme" : "http://www.twitter.com",
  "actions" :
  [{
    "key" : "show_profile",
    "url_format" : "http://www.twitter.com/{{profile_screenname}}"
  }]
 }
]

And JSONKeyPathsByPropertyKey method looks like this:

+ (NSDictionary *)JSONKeyPathsByPropertyKey
{
    return @{
             @"appName" : @"name",
             @"appKey" : @"key",
             @"appURLScheme" : @"app_url_scheme",
             @"appActions" : @"actions",
             @"isInstalled" : NSNull.null
             };
}

So, as you can see there is this isInstalled method which should be ignored during mapping (as there isn't field like this in JSON) but I need to set this property as soon as this Object is fully mapped. What is more I need to set it based on other property provided in JSON. How to achieve this?

I've found solution like this:

@"videoType" : @"@Selector(videoTypeFromString:, type)",

//! implemented on instance you are parsing
- (NSUInteger)videoTypeFromString:(NSString *)type
{
  if ([type isEqualToString:@"shortVideo"]) {
    return VideoTypeShort;
  }

  return VideoTypeLong;
}

But this @selector is never being called...

cojoj
  • 6,405
  • 4
  • 30
  • 52

0 Answers0