{"id":18973,"date":"2017-09-22T16:13:09","date_gmt":"2017-09-22T20:13:09","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=18973"},"modified":"2017-12-20T10:31:13","modified_gmt":"2017-12-20T15:31:13","slug":"swift-proposal-non-exhaustive-enums","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2017\/09\/22\/swift-proposal-non-exhaustive-enums\/","title":{"rendered":"Swift Proposal: Non-Exhaustive Enums"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/jrose-apple\/swift-evolution\/blob\/non-exhaustive-enums\/proposals\/nnnn-non-exhaustive-enums.md\">Jordan Rose<\/a>:<\/p>\n<blockquote cite=\"https:\/\/github.com\/jrose-apple\/swift-evolution\/blob\/non-exhaustive-enums\/proposals\/nnnn-non-exhaustive-enums.md\">\n<p>Currently, adding a new case to an enum is a source-breaking change, which is very inconvenient for library authors. This proposal aims to distinguish between enums that are <em>exhaustive<\/em> (meaning they will never get any new cases) and those that are <em>non-exhaustive,<\/em> and to ensure that clients handle any future cases when dealing with the latter. This change only affects clients from outside the original module.<\/p>\n<p>[&#8230;]<\/p>\n<p>Public enums can be declared as <code>exhaustive<\/code> or as <code>nonexhaustive<\/code>. In Swift 4 mode, the default behavior will be <code>exhaustive<\/code> for source compatibility; in Swift 5 it will be <code>nonexhaustive<\/code>.<\/p>\n<p>When a client tries to switch over a <code>nonexhaustive<\/code> enum, they must include a <code>default<\/code> case unless the enum is declared in the same module as the switch. In Swift 4 mode, omitting this case will result in a warning; in Swift 5, it will be an error.<\/p>\n<p>Enums imported from C will be <code>nonexhaustive<\/code> by default, with a new C-side annotation to make them <code>exhaustive<\/code>. These enums conservatively always have the &ldquo;cross-module&rdquo; behavior.<\/p>\n<\/blockquote>\n\n<p>Update (2017-12-20): See <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/master\/proposals\/0192-non-exhaustive-enums.md\">SE-0192<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Jordan Rose: Currently, adding a new case to an enum is a source-breaking change, which is very inconvenient for library authors. This proposal aims to distinguish between enums that are exhaustive (meaning they will never get any new cases) and those that are non-exhaustive, and to ensure that clients handle any future cases when dealing [&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,71,901],"class_list":["post-18973","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\/18973","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=18973"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/18973\/revisions"}],"predecessor-version":[{"id":19904,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/18973\/revisions\/19904"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=18973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=18973"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=18973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}