<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I’m going to apologise if this has already been proposed a million times before, but I can’t find a way to search the list. I’m a novice here guys :)<div class=""><br class=""></div><div class="">I propose adding a read-only ‘count’ property to enum types, that returns the number of cases; modelled on the API for arrays types.</div><div class=""><br class=""></div><div class="">This has been discussed previously in user communities (e.g. see <a href="http://stackoverflow.com/questions/27094878/how-do-i-get-the-count-of-a-swift-enum" class="">http://stackoverflow.com/questions/27094878/how-do-i-get-the-count-of-a-swift-enum</a>) but it seems to me the proposed solutions are a little complex and inelegant.</div><div class=""><br class=""></div><div class="">To answer the question “what problem does this solve?”, I’m thinking of a situation like this - granted, this is a bit artificial, but imagine if there were a very large number of states…)</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">enum</span> Tristate: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span> High = <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span> Low</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span> Off</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">mutating</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> next() {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> nextState = (<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">rawValue</span> + <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span>) % <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Tristate</span>.count</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span> = <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Tristate</span>(rawValue: nextState)!</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">thanks, Martin</div><div class=""><div class=""><br class=""></div><div class=""><br class=""></div></div></body></html>