{"id":17791,"date":"2017-04-20T14:06:12","date_gmt":"2017-04-20T18:06:12","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=17791"},"modified":"2017-04-20T14:06:12","modified_gmt":"2017-04-20T18:06:12","slug":"naming-swift-extensions","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2017\/04\/20\/naming-swift-extensions\/","title":{"rendered":"Naming Swift Extensions"},"content":{"rendered":"<p><a href=\"https:\/\/owensd.io\/2017\/04\/20\/extensions-and-categories\/\">David Owens II<\/a>:<\/p>\n<blockquote cite=\"https:\/\/owensd.io\/2017\/04\/20\/extensions-and-categories\/\">\n<p>There&rsquo;s a lot of talk about how extensions are used for code organization. This is even one of the primary defenses for some of the Swift proposals. However, it&rsquo;s missing a key component of organization: categorization.<\/p>\n<p>If you remember when dinosaurs roamed the Earth, they wrote code to maneuver their space ships with a language that must have been from aliens: Objective-C.<\/p>\n<p>If you wanted to extend a type and provide yourself some new goodies, you would do so like this:<\/p>\n<pre>@implementation Raptor (BirdOfPrey)\n\/\/ new cool stuff here\n@end<\/pre>\n<p>In Swift, however, it&rsquo;s not as clear what we should do.<\/p>\n<\/blockquote>\n<p>There are several different options, none of them ideal. With Objective-C, you would actually see <code>@implementation Raptor (BirdOfPrey)<\/code> in the Document Items pop-up menu in Xcode. As far as I can tell, there&rsquo;s no way to get the Swift type name and category name into a single menu item like that. I have been using:<\/p>\n<pre>extension Raptor { \/\/ MARK: BirdOfPrey\n    \/\/ new cool stuff here\n}\n<\/pre>\n<p>To me, this adds the least noise while also making the category name stand out a bit in the source. <code>BirdOfPrey<\/code> will also show up in the menu, indented under <code>Raptor<\/code>.<\/p>\n<p>Previously: <a href=\"https:\/\/mjtsai.com\/blog\/2016\/07\/26\/swift-type-aliases\/\">Swift Type Aliases<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>David Owens II: There&rsquo;s a lot of talk about how extensions are used for code organization. This is even one of the primary defenses for some of the Swift proposals. However, it&rsquo;s missing a key component of organization: categorization. If you remember when dinosaurs roamed the Earth, they wrote code to maneuver their space ships [&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,54,71,901,226],"class_list":["post-17791","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-languagedesign","tag-objective-c","tag-programming","tag-swift-programming-language","tag-xcode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/17791","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=17791"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/17791\/revisions"}],"predecessor-version":[{"id":17792,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/17791\/revisions\/17792"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=17791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=17791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=17791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}