{"id":28901,"date":"2020-05-08T16:02:33","date_gmt":"2020-05-08T20:02:33","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=28901"},"modified":"2020-05-08T16:02:33","modified_gmt":"2020-05-08T20:02:33","slug":"resilient-decoding-in-swift","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2020\/05\/08\/resilient-decoding-in-swift\/","title":{"rendered":"Resilient Decoding in Swift"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/airbnb\/ResilientDecoding\">Airbnb<\/a>:<\/p>\n<blockquote cite=\"https:\/\/github.com\/airbnb\/ResilientDecoding\">\n<p>This package defines mechanisms to partially recover from errors when decoding <code>Decodable<\/code> types. It also aims to provide an ergonomic API for inspecting decoding errors during development and reporting them in production.<\/p>\n<p>[&#8230;]<\/p>\n<p>After running this code, <code>foo<\/code> will be a <code>Foo<\/code> where <code>foo.array == [1, 3]<\/code> and <code>foo.value == nil<\/code>. In DEBUG, <code>foo.$array.results<\/code> will be <code>[.success(1), .failure(DecodingError.dataCorrupted(&#8230;), .success(3)]<\/code> and <code>foo.$value.error<\/code> will be <code>DecodingError.dataCorrupted(&#8230;)<\/code>. This functionality is <code>DEBUG<\/code>-only so that we can maintain <a href=\"https:\/\/github.com\/airbnb\/ResilientDecoding\/blob\/8fac9a34b7cff8c8849081dee2630b8958f695cc\/Tests\/ResilientDecodingTests\/MemoryTests.swift#L8-L20\">no overhead in release builds<\/a>.<\/p>\n<\/blockquote>\n<p>Cool use of Swift property wrappers and projected values.<\/p>\n\n<p>See also:<\/p>\n<ul>\n<li><a href=\"http:\/\/marksands.github.io\/2019\/10\/21\/better-codable-through-property-wrappers.html\">Better Codable Through Property Wrappers<\/a><\/li>\n<li><a href=\"https:\/\/medium.com\/flawless-app-stories\/how-can-property-wrappers-and-function-builders-be-leveraged-d43160de338f\">How can Property Wrappers and Function Builders be leveraged?<\/a><\/li>\n<li><a href=\"http:\/\/objcolumnist.com\/2019\/09\/18\/implementing-the-service-locator-pattern-using-a-property-wrapper-in-swift-5-1\/\">Implementing the Service Locator Pattern using a Property Wrapper in Swift 5.1<\/a><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=dZ0gvRjmlFM\">Using and creating Property Wrappers<\/a><\/li>\n<li><a href=\"https:\/\/medium.com\/flawless-app-stories\/turning-property-wrappers-into-function-wrappers-2be3a49229f5\">Turning Property Wrappers into Function Wrappers<\/a><\/li>\n<\/ul>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/05\/07\/facebook-sdk-causes-crashes\/\">Facebook SDK Causes Crashes<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/03\/24\/making-swift-properties-overridable-only-in-debug-builds\/\">Making Swift Properties Overridable Only in Debug Builds<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2019\/06\/25\/swift-property-wrappers\/\">Swift Property Wrappers<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Airbnb: This package defines mechanisms to partially recover from errors when decoding Decodable types. It also aims to provide an ergonomic API for inspecting decoding errors during development and reporting them in production. [&#8230;] After running this code, foo will be a Foo where foo.array == [1, 3] and foo.value == nil. In DEBUG, foo.$array.results [&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":"2020-05-08T20:02:36Z","apple_news_api_id":"9240c888-039f-4c60-ab77-d325dc124654","apple_news_api_modified_at":"2020-05-08T20:02:37Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AkkDIiAOfTGCrd9Ml3BJGVA","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":[1165,74,71,1774,901],"class_list":["post-28901","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-airbnb","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\/28901","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=28901"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/28901\/revisions"}],"predecessor-version":[{"id":28902,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/28901\/revisions\/28902"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=28901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=28901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=28901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}