{"id":14758,"date":"2016-06-08T10:56:01","date_gmt":"2016-06-08T14:56:01","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=14758"},"modified":"2016-06-08T10:56:01","modified_gmt":"2016-06-08T14:56:01","slug":"swift-mistakes","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/06\/08\/swift-mistakes\/","title":{"rendered":"Swift Mistakes"},"content":{"rendered":"<p><a href=\"http:\/\/www.raizlabs.com\/dev\/2016\/04\/swift-mistakes-ive-made\/\">Zev Eisenberg<\/a>:<\/p>\n<blockquote cite=\"http:\/\/www.raizlabs.com\/dev\/2016\/04\/swift-mistakes-ive-made\/\"><p>Even though I&rsquo;ve been keeping up with Swift blog posts, my first Swift app was a port of an old and crusty Objective-C code base, and I carried over a lot of old habits. In looking back over it, I found many small- to medium-sized changes that make the code cleaner and more Swifty. Maybe I can help you avoid similar mistakes.<\/p><p>[&#8230;]<\/p><p>Sadly, you can&rsquo;t make protocol conformances\n<code>private<\/code>, but otherwise you should be using\n<code>private extension<\/code>s wherever you aren&rsquo;t required to make them public.<\/p><p>[&#8230;]<\/p><p>There are certainly cases where direct comparison to <code>nil<\/code> are appropriate, but Swift&rsquo;s language features make it pretty rare in my experience.<\/p><p>[&#8230;]<\/p><p>Since you can extend any type, it&rsquo;s convenient to make extension files for your utilities on\n<code>CGRect<\/code>,\n<code>CGPoint<\/code>,\n<code>UIInterfaceOrientation<\/code>, and other types that couldn&rsquo;t be extended when they were lowly C structs. So don&rsquo;t litter your main code files with one-off domain-specific utilities on system types. Put them in a separate file and write a couple of unit tests just for that file.<\/p><\/blockquote>\n\n<p><a href=\"http:\/\/indiestack.com\/2016\/05\/implicitly-crashing-optionals\/\">Daniel Jalkut<\/a>:<\/p>\n<blockquote cite=\"http:\/\/indiestack.com\/2016\/05\/implicitly-crashing-optionals\/\">\n<p>At first, I didn&rsquo;t think too much of this bridging header. Sure, I want to access my Objective C files from Swift. Which ones? <em>Why not all of them?<\/em><\/p>\n<p>[&#8230;]<\/p>\n<p>My takeaway is to accept that it is <em>fundamentally unsafe<\/em> to interface with Objective C classes whose headers have not been audited for nullability.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Zev Eisenberg: Even though I&rsquo;ve been keeping up with Swift blog posts, my first Swift app was a port of an old and crusty Objective-C code base, and I carried over a lot of old habits. In looking back over it, I found many small- to medium-sized changes that make the code cleaner and more [&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":[71,901],"class_list":["post-14758","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14758","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=14758"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14758\/revisions"}],"predecessor-version":[{"id":14759,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14758\/revisions\/14759"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=14758"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=14758"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=14758"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}