{"id":14760,"date":"2016-06-08T10:56:14","date_gmt":"2016-06-08T14:56:14","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=14760"},"modified":"2016-06-08T10:56:14","modified_gmt":"2016-06-08T14:56:14","slug":"swift-configuration-and-then","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/06\/08\/swift-configuration-and-then\/","title":{"rendered":"Swift Configuration and &ldquo;then&rdquo;"},"content":{"rendered":"<p><a href=\"http:\/\/khanlou.com\/2016\/06\/configuration-in-swift\/\">Soroush Khanlou<\/a>:<\/p>\n<blockquote cite=\"http:\/\/khanlou.com\/2016\/06\/configuration-in-swift\/\"><p>I toyed around with a few ways to fix this issue, including making the instance variables optional and filling in the defaults at the usage site, but that ended up being just as clunky as the big initializer. What I settled on was: instead of making the variables <em>optional<\/em>, I made them mutable. That solves quite a few problems.<\/p><p>[&#8230;]<\/p><p>The <code>then<\/code> extension is a really useful library to have in your app. [&#8230;] Since everything in Cocoa Touch inherits from <code>NSObject<\/code>, you can now use this function to configure lots of types, and you can do so <em>at the declaration of the property<\/em>. Swift will let you initialize things in-line (as long as they&rsquo;re effectively a one line expression) [&#8230;]<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Soroush Khanlou: I toyed around with a few ways to fix this issue, including making the instance variables optional and filling in the defaults at the usage site, but that ended up being just as clunky as the big initializer. What I settled on was: instead of making the variables optional, I made them mutable. [&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":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","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,30,71,901],"class_list":["post-14760","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-ios","tag-mac","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14760","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=14760"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14760\/revisions"}],"predecessor-version":[{"id":14761,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14760\/revisions\/14761"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=14760"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=14760"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=14760"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}