{"id":32293,"date":"2021-04-28T17:07:09","date_gmt":"2021-04-28T21:07:09","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=32293"},"modified":"2021-04-28T19:25:37","modified_gmt":"2021-04-28T23:25:37","slug":"swift-generics-2-existentials-boogaloo","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2021\/04\/28\/swift-generics-2-existentials-boogaloo\/","title":{"rendered":"Swift Generics 2: Existentials Boogaloo"},"content":{"rendered":"<p><a href=\"https:\/\/www.timekl.com\/blog\/2021\/04\/26\/swift-generics-2-existentials-boogaloo\/\">Tim Ekl<\/a>:<\/p>\n<blockquote cite=\"https:\/\/www.timekl.com\/blog\/2021\/04\/26\/swift-generics-2-existentials-boogaloo\/\"><p>It&rsquo;s been just over two years since we first saw &ldquo;<a href=\"https:\/\/forums.swift.org\/t\/improving-the-ui-of-generics\/22814\">Improving the UI of\ngenerics<\/a>,&rdquo; the discussion post about potential changes to make\ngeneric types easier to work with in Swift, and <em>five<\/em> years since the first\nversion of the Swift <a href=\"https:\/\/github.com\/apple\/swift\/blob\/main\/docs\/GenericsManifesto.md\">Generics Manifesto<\/a>. (Time flies when you&rsquo;re\nbuilding a language!) Last week, generics landed back in the spotlight, as\nAnthony Latsis, Filip Sakel, and Suyash Srijan proposed <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0309-unlock-existential-types-for-all-protocols.md\">SE-0309<\/a>, with\na major change that addresses one of the most infamous errors in Swift:<\/p><blockquote><p>Protocol can only be used as a generic constraint because it has &lsquo;Self&rsquo; or\nassociated type requirements.<\/p><\/blockquote><p>While this change is still in review (through May 1), it looks very promising &mdash;\nbut, as often happens when dealing with the corners of the type system, the\ndetails can be a bit opaque. Much like <a href=\"\/blog\/2019\/04\/14\/swift-generics-evolution\/\">last time<\/a>, this post\nwill walk through the nitty-gritty of the proposed changes in SE-0309, and offer\nsome practical scenarios where they might improve day-to-day Swift usage.<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2019\/04\/10\/improving-the-ui-of-swift-generics\/\">Improving the UI of Swift Generics<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2018\/11\/29\/lifting-the-self-or-associated-type-constraint-on-swift-existentials\/\">Lifting the &ldquo;Self or associated type&rdquo; Constraint on Swift Existentials<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2018\/02\/28\/swift-protocols-wishlist\/\">Swift Protocols Wishlist<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2017\/12\/20\/patterns-for-working-with-associated-types\/\">Patterns for Working With Associated Types<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2016\/06\/01\/swift-type-erasure\/\">Swift Type Erasure<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2016\/02\/19\/swift-protocols-with-associated-types\/\">Swift Protocols With Associated Types<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2015\/06\/22\/swift-protocols-question\/\">Swift Protocols Question<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Tim Ekl: It&rsquo;s been just over two years since we first saw &ldquo;Improving the UI of generics,&rdquo; the discussion post about potential changes to make generic types easier to work with in Swift, and five years since the first version of the Swift Generics Manifesto. (Time flies when you&rsquo;re building a language!) Last week, generics [&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":"2021-04-28T21:07:13Z","apple_news_api_id":"d72ddc88-249f-4e64-837e-7bb8e41594a6","apple_news_api_modified_at":"2021-04-28T23:25:41Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/A1y3ciCSfTmSDfnu45BWUpg","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-32293","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\/32293","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=32293"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/32293\/revisions"}],"predecessor-version":[{"id":32295,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/32293\/revisions\/32295"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=32293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=32293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=32293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}