{"id":13122,"date":"2015-12-16T08:44:07","date_gmt":"2015-12-16T13:44:07","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=13122"},"modified":"2015-12-16T08:45:15","modified_gmt":"2015-12-16T13:45:15","slug":"swift-type-constrained-extensions","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2015\/12\/16\/swift-type-constrained-extensions\/","title":{"rendered":"Swift Type Constrained Extensions"},"content":{"rendered":"<p><a href=\"http:\/\/www.cimgf.com\/2015\/12\/14\/swift-type-constrained-extensions-express-yourself\/\">Matt Long<\/a>:<\/p>\n<blockquote cite=\"http:\/\/www.cimgf.com\/2015\/12\/14\/swift-type-constrained-extensions-express-yourself\/\">\n<p>One of Swift&rsquo;s most expressive and powerful features is type constrained extensions. If you&rsquo;re new to Swift coming from Objective-C, think of it as a category in Objective-C yet with the ability to specify type criteria so that your category (extension) only applies to the class <em>if<\/em> it conforms to a certain type. For example, if you have an array of your own custom objects, you can create functions that are specific to an array of your objects.<\/p>\n<\/blockquote>\n<p>His JSON example seems like a bit much, but I like the idea of extending collections with helpers for particular types. Because of the type system, this doesn&rsquo;t pollute the namespace, and you will get relevant code completions from the IDE. In Objective-C, I would use a free function (with the type in its name) or a class method, both of which are more cumbersome.<\/p>","protected":false},"excerpt":{"rendered":"<p>Matt Long: One of Swift&rsquo;s most expressive and powerful features is type constrained extensions. If you&rsquo;re new to Swift coming from Objective-C, think of it as a category in Objective-C yet with the ability to specify type criteria so that your category (extension) only applies to the class if it conforms to a certain type. [&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":[27,46,71,901],"class_list":["post-13122","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-craft","tag-languagedesign","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13122","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=13122"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13122\/revisions"}],"predecessor-version":[{"id":13123,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13122\/revisions\/13123"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=13122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=13122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=13122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}