{"id":24918,"date":"2019-04-08T16:02:19","date_gmt":"2019-04-08T20:02:19","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=24918"},"modified":"2019-04-08T16:02:19","modified_gmt":"2019-04-08T20:02:19","slug":"codextended-extension-for-swifts-codable","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2019\/04\/08\/codextended-extension-for-swifts-codable\/","title":{"rendered":"Codextended: Extension for Swift&rsquo;s Codable"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/JohnSundell\/Codextended\">John Sundell<\/a> (<a href=\"https:\/\/twitter.com\/johnsundell\/status\/1115229848635678727\">tweet<\/a>):<\/p>\n<blockquote cite=\"https:\/\/github.com\/JohnSundell\/Codextended\"><p>However, once some form of customization is needed &mdash; for example to transform parts of the decoded data, or to provide default values for certain keys &mdash; the standard <code>Codable<\/code> API starts to become <em>really<\/em> verbose. It also doesn&rsquo;t take advantage of Swift&rsquo;s robust type inference capabilities, which produces a lot of unnecessary boilerplate.<\/p>\n<p>That&rsquo;s what Codextended aims to fix.<\/p>\n<p>[&#8230;]<\/p>\n<p><code>Codable<\/code> already comes with support for custom date formats through assigning a <code>DateFormatter<\/code> to either a <code>JSONEncoder<\/code> or <code>JSONDecoder<\/code>. However, requiring each call site to be aware of the specific date formats used for each type isn&rsquo;t always great &mdash; so with Codextended, it&rsquo;s easy for a type itself to pick what date format it needs to use.<\/p>\n<\/blockquote>\n\n<p>Previously: <a href=\"https:\/\/mjtsai.com\/blog\/2019\/01\/18\/even-more-about-swifts-codable\/\">Even More About Swift&rsquo;s Codable<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>John Sundell (tweet): However, once some form of customization is needed &mdash; for example to transform parts of the decoded data, or to provide default values for certain keys &mdash; the standard Codable API starts to become really verbose. It also doesn&rsquo;t take advantage of Swift&rsquo;s robust type inference capabilities, which produces a lot of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2019-04-08T20:02:21Z","apple_news_api_id":"30ecb47b-dbda-4aac-9443-c7b759bd3323","apple_news_api_modified_at":"2019-04-08T20:02:24Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AMOy0e9vaSqyUQ8e3Wb0zIw","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[74,71,1774,901],"class_list":["post-24918","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-opensource","tag-programming","tag-swift-codable","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/24918","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=24918"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/24918\/revisions"}],"predecessor-version":[{"id":24919,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/24918\/revisions\/24919"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=24918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=24918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=24918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}