Open ParthaGudivada opened 11 years ago
How would you like the converter to decide between which of the formats it should use?
Can the following rules be included :
a) if the convert block has specific reference to the attribute name, allow the specific format.
b) Otherwise, switch to the default one.
Could you give me a code example of the API you'd like? Perhaps a general solution would be something like an NSSDictionary
of property names to ConvertBlock
s, so we'd first check if a property has a particular convert block, and if so use that?
[converter forPropertyName: @"firstDate" setConvertBlock:^(id d1)
{
return [NSDate convertFromStringDate:d1 usingFormatterString:@"DT_yyyy_MM_dd_HH_mm_ss"];
}
];
It makes sense to follow the approach suggested.
If the json object has two date string objects (say, 2013-03-02, 2013-03-02 10:15), can't the convertToDate message handle these formats.
JAGPropertyConverter *converter = [[JAGPropertyConverter alloc] initWithOutputType:kJAGJSONOutput] ;
[converter setConvertToDate:^(id d1) { return [NSDate convertFromStringDate:d1 usingFormatterString:DT_yyyy_MM_dd_HH_mm_ss]; } ];
I have written a custom method on NSDate to convert different string date formats. What I am seeing is that, I can use only one at any point of time.
Commenting either of the above works fine for the individual date string objects. However if uncomment both of the above, only one gets converted. This lead me to believe that I can convert only one date string object ? Am I missing something. Thanks in advance for your reply.