{"id":16072,"date":"2016-10-14T15:44:21","date_gmt":"2016-10-14T19:44:21","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=16072"},"modified":"2016-10-14T15:44:21","modified_gmt":"2016-10-14T19:44:21","slug":"swifty-delegates","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/10\/14\/swifty-delegates\/","title":{"rendered":"Swifty Delegates"},"content":{"rendered":"<p><a href=\"http:\/\/khanlou.com\/2016\/09\/swifty-delegates\/\">Soroush Khanlou<\/a>:<\/p>\n<blockquote cite=\"http:\/\/khanlou.com\/2016\/09\/swifty-delegates\/\"><p>These are horrible. Why are both of these methods called <code>messageForm<\/code>? Also, starting a method with a noun here doesn&rsquo;t make sense: it usually suggests that you&rsquo;ll be returning an object of that type (think about <code>data(using:)<\/code> on <code>NSString<\/code>, which returns a <code>Data<\/code>). We&rsquo;re not returning any message form objects here. That &ldquo;message form&rdquo; is actually the name of the first parameter. These are very confusing method names!<\/p><p>Both of these types of delegate methods can be fixed by moving the &ldquo;sender&rdquo; to the back of the line, and bringing the verbs forward. For the first one, the event that the sender is informing the delegate about is <code>didTapCancel<\/code>, instead of <code>messageFormDidTapCancel<\/code>.<\/p>\n<p>[&#8230;]<\/p>\n<p>I haven&rsquo;t found a hard and fast rule for which preposition to use yet. I&rsquo;ve found &ldquo;on&rdquo;, &ldquo;for&rdquo;, &ldquo;with&rdquo;, and &ldquo;in&rdquo; to all be useful in different circumstances.<\/p>\n<p>[&#8230;]<\/p>\n<p>These rules aren&rsquo;t endorsed by anyone except for me, but I think they make much more sense than the current rules by which we write delegate methods. Going forward, I&rsquo;ll probably start writing my Swift delegate methods with this structure.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Soroush Khanlou: These are horrible. Why are both of these methods called messageForm? Also, starting a method with a noun here doesn&rsquo;t make sense: it usually suggests that you&rsquo;ll be returning an object of that type (think about data(using:) on NSString, which returns a Data). We&rsquo;re not returning any message form objects here. That &ldquo;message [&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":[69,27,31,30,71,901],"class_list":["post-16072","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-craft","tag-ios","tag-mac","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/16072","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=16072"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/16072\/revisions"}],"predecessor-version":[{"id":16073,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/16072\/revisions\/16073"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=16072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=16072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=16072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}