{"id":9029,"date":"2014-06-22T13:44:00","date_gmt":"2014-06-22T17:44:00","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=9029"},"modified":"2014-06-22T13:44:00","modified_gmt":"2014-06-22T17:44:00","slug":"interesting-swift-features","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2014\/06\/22\/interesting-swift-features\/","title":{"rendered":"Interesting Swift Features"},"content":{"rendered":"<p><a href=\"https:\/\/www.mikeash.com\/pyblog\/friday-qa-2014-06-20-interesting-swift-features.html\">Mike Ash<\/a>:<\/p><blockquote cite=\"https:\/\/www.mikeash.com\/pyblog\/friday-qa-2014-06-20-interesting-swift-features.html\"><p>Because the collections use generic types, they have no problem containing <code>struct<\/code>s. Object members work without difficulty. They basically become pass-by-value objects rather than a totally different entity.<\/p><p>The result is that small model classes become a lot nicer in Swift. How many times have you used an <code>NSMutableDictionary<\/code> with a few fixed keys to represent a bag of related data that really should have been a class? If you&rsquo;re like me, the answer is &ldquo;too many&rdquo;. That&rsquo;s because making a simple Objective-C class is a bit of a pain.<\/p><p>[&#8230;]<\/p><p>[The trailing closures feature] is interesting because it knocks down a visual barrier separating language constructs from library calls. As I <a href=\"https:\/\/www.mikeash.com\/pyblog\/friday-qa-2008-12-26.html\">discussed way back in 2008<\/a>, blocks are a great addition to Objective-C because they allow you to write your own control constructs. This showed up in a huge way with GCD, which could provide a ton of useful asynchronous calls that worked a lot like language constructs, but were implemented as library calls. However, with Objective-C, there&rsquo;s still a <em>syntactic<\/em> difference in how you write calls with blocks compared to how you use built-in language constructs.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Mike Ash:Because the collections use generic types, they have no problem containing structs. Object members work without difficulty. They basically become pass-by-value objects rather than a totally different entity.The result is that small model classes become a lot nicer in Swift. How many times have you used an NSMutableDictionary with a few fixed keys to [&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-9029","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\/9029","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=9029"}],"version-history":[{"count":0,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/9029\/revisions"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=9029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=9029"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=9029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}