<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Protocol on ZK Punk</title>
		<link>https://www.ZKPunk.dev/tags/protocol/</link>
		<description>Recent content in Protocol on ZK Punk</description>
		<generator>Hugo</generator>
		<language>en</language>
		
		
		
		
			<lastBuildDate>Tue, 21 Jul 2020 22:04:00 -0700</lastBuildDate>
		
			<atom:link href="https://www.ZKPunk.dev/tags/protocol/index.xml" rel="self" type="application/rss+xml" />
			<item>
				<title>Usage of CaseIterable in Swift Enum</title>
				<link>https://www.ZKPunk.dev/tips/usage-of-case-iterable-in-swift/</link>
				<pubDate>Tue, 21 Jul 2020 22:04:00 -0700</pubDate>
				<guid>https://www.ZKPunk.dev/tips/usage-of-case-iterable-in-swift/</guid>
				<description>&lt;p&gt;Last Run on XCODE 11.6 / Swift 5.2&lt;/p&gt;&#xA;&lt;h3 id=&#34;definition&#34;&gt;&#xA;  Definition&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#definition&#34;&gt;&#xA;    &lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34; title=&#34;Link to heading&#34;&gt;&lt;/i&gt;&#xA;    &lt;span class=&#34;sr-only&#34;&gt;Link to heading&lt;/span&gt;&#xA;  &lt;/a&gt;&#xA;&lt;/h3&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://developer.apple.com/documentation/swift/caseiterable&#34;&gt;CaseIterable&lt;/a&gt; is a protocol in Swift, that typically lets an enumeration to provide all of its cases as a collection.&lt;/p&gt;&#xA;&lt;p&gt;Lets look at a simple example from my RoadRage car game. This is an enum type called TrafficType listing the cases of traffic/obstacle Sprites generated in my RoadRage car game.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;enum&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;TrafficType&lt;/span&gt;: UInt32 {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; Police&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; Ambulance&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; FireTruck&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; Van&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; SportsCar&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; Taxi&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In my game I would like to find out the total count of the TrafficType entities. I would also like the ability to randomly pick a  traffic object from the list to keep generating obstacles during the game loop. And to achive that is as simple as conforming to the &lt;a href=&#34;https://developer.apple.com/documentation/swift/caseiterable&#34;&gt;CaseIterable&lt;/a&gt; protocol in the enum.&lt;/p&gt;</description>
			</item>
	</channel>
</rss>
