<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>on 19 Oct 2017 11:21:39 -0700 Eagle Offshore <<a href="mailto:eagleoffshore@mac.com">eagleoffshore@mac.com</a>> wrote:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Yes, in general, I think Codable is a poor solution for json decoding just like I never used NSCoding to convert JSON to and from objects. It feels clumsy.<br>
<br>
I found it a much better solution to add a category to NSObject that had<br>
<br>
-(NSData*)<wbr>toJSONRepresentationWithMappin<wbr>gs:(NSDictionary*)d<br>
+()fromJSONRepresentation:(<wbr>NSData*) mappings:(NSDictionary*)d<br>
<br>
where mappings might be { @"firstName": @"first_name", etc.... }<br>
<br>
and was simple to write a general solution using introspection and KVC.<br>
<br>
Codable is a limited one trick pony that would be trivial to write as a trait or extension if Swift provided the more profound thing - introspection and reflection. A whole world of opportunities would open up with that and we could stop wasting time on Codable and KeyPath - neither of which is that useful when working with string data from the wild.<br></blockquote><div><br></div><div>i found Codable very useful. when you need to translate the keys it's a bit awkward and looks "unfinished" but if you don't need the translation you literally write no code at all which is good.</div><div><br></div><div>having Codable does not contradict having introspection / reflection. general (or shall we say custom) approaches that use introspection / reflection tend to work much slower (from Objective-C experience). i have no data if Codable is performant in these regards but at least it has a potential to be more optimal than a general solution based on introspection / reflection.</div><div><br></div><div>Mike</div><div><br></div></div></div></div>