{"id":11208,"date":"2015-05-13T09:35:51","date_gmt":"2015-05-13T13:35:51","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=11208"},"modified":"2015-05-13T09:35:51","modified_gmt":"2015-05-13T13:35:51","slug":"swift-the-unused-optional-value-problem","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2015\/05\/13\/swift-the-unused-optional-value-problem\/","title":{"rendered":"Swift: the Unused Optional Value Problem"},"content":{"rendered":"<p><a href=\"http:\/\/natashatherobot.com\/swift-unused-optional-value\/\">Natasha Murashev<\/a>:<\/p>\n<blockquote cite=\"http:\/\/natashatherobot.com\/swift-unused-optional-value\/\"><p>Here is a scenario &#8211; you need to do something in your code based on whether an optional value exists or not, but the thing you need to do does not need to actually use the optional value.<\/p>\n<p>[&#8230;]<\/p>\n<p>This immediately stood out as &ldquo;wrong&rdquo; to me. By now, I&rsquo;m very well trained to unwrap optionals all the time, so having a <code>!= nil<\/code> just feels wrong in Swift. Also, I don&rsquo;t like the <code>!=<\/code> here &#8211; I had to do a double take to realize that this code executes if something is actually there, so to me, it&rsquo;s also not as readable. Of course, this code works and is completely &ldquo;correct&rdquo; for the situation, if that&rsquo;s what you prefer.<\/p><\/blockquote>\n<p><a href=\"http:\/\/owensd.io\/2015\/05\/12\/optionals-if-let.html\">David Owens II<\/a>:<\/p>\n<blockquote cite=\"http:\/\/owensd.io\/2015\/05\/12\/optionals-if-let.html\">\n<p>It just doesn&rsquo;t feel semantically correct. The optional is not <code>nil<\/code>, it specifically\nhas a value of <code>None<\/code>. I&rsquo;ve never liked this syntax; I&rsquo;ve talked about it before - thankfully the <code>bool<\/code>\ncomparison has been lost, but the <code>nil<\/code> check still sits wrong with me.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Natasha Murashev: Here is a scenario &#8211; you need to do something in your code based on whether an optional value exists or not, but the thing you need to do does not need to actually use the optional value. [&#8230;] This immediately stood out as &ldquo;wrong&rdquo; to me. By now, I&rsquo;m very well trained [&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":[46,71,901],"class_list":["post-11208","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-languagedesign","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11208","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=11208"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11208\/revisions"}],"predecessor-version":[{"id":11209,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11208\/revisions\/11209"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=11208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=11208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=11208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}