{"id":30720,"date":"2020-11-17T15:44:59","date_gmt":"2020-11-17T20:44:59","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=30720"},"modified":"2020-11-17T15:44:59","modified_gmt":"2020-11-17T20:44:59","slug":"does-swift-call-the-protocol-extension-or-subclass-implementation","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2020\/11\/17\/does-swift-call-the-protocol-extension-or-subclass-implementation\/","title":{"rendered":"Does Swift Call the Protocol Extension or Subclass Implementation?"},"content":{"rendered":"<p><a href=\"https:\/\/twitter.com\/simjp\/status\/1328729653440360450\">JP Simard<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/simjp\/status\/1328729653440360450\">\n<p>Pop Quiz, what does this Swift program print?<\/p>\n<p>5 years on, it still takes me a few tries to properly reason through this. Especially in the real world when the code is a bit more spread out or complex to fit in a tweet.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/gregtitus\/status\/1328740446852550657\">Greg Titus<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/gregtitus\/status\/1328740446852550657\"><p>What is going on here is that the <code>MyProtocol<\/code> conformance is on <code>MySuperclass<\/code>. Thus the witnesses are determined right there, and since <code>MySuperclass<\/code> doesn&rsquo;t implement <code>myFunction<\/code>, the conformance uses the fallback implementation in the extension.<\/p><p>Subclasses don&rsquo;t\/can&rsquo;t &ldquo;re-conform&rdquo;<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2015\/09\/01\/swift-protocols\/\">Swift Protocols<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>JP Simard: Pop Quiz, what does this Swift program print? 5 years on, it still takes me a few tries to properly reason through this. Especially in the real world when the code is a bit more spread out or complex to fit in a tweet. Greg Titus: What is going on here is that [&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":"2020-11-17T20:45:03Z","apple_news_api_id":"95f73c5d-4abe-425f-b6a9-784cc6b04af3","apple_news_api_modified_at":"2020-11-17T20:45:03Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/Alfc8XUq-Ql-2qXhMxrBK8w","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-30720","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\/30720","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=30720"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/30720\/revisions"}],"predecessor-version":[{"id":30721,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/30720\/revisions\/30721"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=30720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=30720"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=30720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}