{"id":27567,"date":"2019-12-13T16:55:15","date_gmt":"2019-12-13T21:55:15","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=27567"},"modified":"2025-12-16T15:49:30","modified_gmt":"2025-12-16T20:49:30","slug":"userdefaults-access-via-property-wrappers","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2019\/12\/13\/userdefaults-access-via-property-wrappers\/","title":{"rendered":"UserDefaults Access via Property Wrappers"},"content":{"rendered":"<p><a href=\"https:\/\/christiantietze.de\/posts\/2019\/12\/userdefaults-property-wrappers\/\">Christian Tietze<\/a>:<\/p>\n<blockquote cite=\"https:\/\/christiantietze.de\/posts\/2019\/12\/userdefaults-property-wrappers\/\">\n<p>The hip and cool property-wrapper implementations on the web so far ignore the <code>registerDefaults<\/code> layer completely and provide a local fallback if no value for the key is persisted for the current&nbsp;user.<\/p>\n<p>The problem I see here is that you don&rsquo;t have a <em>shared<\/em> default value anymore. Knowledge of the default value is local to the property declaration in a concrete type.<\/p>\n<\/blockquote>\n<p>A full solution would include something like:<\/p>\n<ol>\n<li>A pair type that combines a key with a default value.<\/li>\n<li>A connection between that and <code>UserDefaults<\/code> for getting and setting values.<\/li>\n<li>A way to access predefined pairs from different places in your code.<\/li>\n<li>A full list of the predefined pairs so that they can be registered.<\/li>\n<li>A way to link a property to a pair and a given instance of <code>UserDefaults<\/code>.<\/li>\n<\/ol>","protected":false},"excerpt":{"rendered":"<p>Christian Tietze: The hip and cool property-wrapper implementations on the web so far ignore the registerDefaults layer completely and provide a local fallback if no value for the key is persisted for the current&nbsp;user. The problem I see here is that you don&rsquo;t have a shared default value anymore. Knowledge of the default value is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2019-12-13T21:55:19Z","apple_news_api_id":"714b5350-a617-4a64-ba23-f7bfdca387fa","apple_news_api_modified_at":"2025-12-16T20:49:32Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/AcUtTUKYXSmS6I_e_3KOH-g","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":[69,31,1667,30,1666,2868,71,901],"class_list":["post-27567","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-ios","tag-ios-13","tag-mac","tag-macos-10-15","tag-nsuserdefaults","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/27567","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=27567"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/27567\/revisions"}],"predecessor-version":[{"id":27568,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/27567\/revisions\/27568"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=27567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=27567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=27567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}