<div dir="ltr">Hi Nevin (et al) <div><br></div><div>Here&#39;s the relevant section of my code. It&#39;s from a protocol I use called &quot;ParameterSet&quot; to extend OptionSets to contain small numbers (like an Enum with an associated type, but all the data is stored in the UInt). Wouldn&#39;t be my first choice to share, as it breaks KISS. Anyhow, the &quot;ExpressibleByDictionaryLiteral&quot; lets me specify a &quot;params&quot; template tersely. I only found out how to use the -Literal initializers last year. I love them.</div><div><div><br></div><div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span>struct DrumNote: ParameterSet {</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>let rawValue: UInt</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>static let params: [ParamType] = [ [&quot;velocity&quot;:0...255], &quot;flam&quot;, &quot;roll&quot;, &quot;reverse&quot; ]</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>static let</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>velocity<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>= param(0),</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>flam<span class="gmail-Apple-tab-span" style="white-space:pre">                </span>= param(1),</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>roll<span class="gmail-Apple-tab-span" style="white-space:pre">                </span>= param(2),</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>reverse<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>= param(3),</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>// ...</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span>}</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span>enum ParamType: ExpressibleByStringLiteral, ExpressibleByDictionaryLiteral {</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>public init( dictionaryLiteral elements: (String,Any)... ) {</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>if let pair = elements.first as? (String,ClosedRange&lt;FloatLiteralType&gt;) { self = .doub(pair.0,pair.1) }</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>else if let pair = elements.first as? (String,CountableClosedRange&lt;IntegerLiteralType&gt;) { self = .int(pair.0, pair.1.lowerBound ... pair.1.upperBound ) }</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>else { fatalError(&quot;Can only init from Double...Double or Int...Int&quot;) }</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>}</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>// ...</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                        </span></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span>}</div></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 9, 2018 at 6:10 PM, Nevin Brackett-Rozinsky <span dir="ltr">&lt;<a href="mailto:nevin.brackettrozinsky@gmail.com" target="_blank">nevin.brackettrozinsky@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jan 9, 2018 at 7:47 PM, <a href="mailto:charles@charlesism.com" target="_blank">charles@charlesism.com</a> <span dir="ltr">&lt;<a href="mailto:charlesism.com@gmail.com" target="_blank">charlesism.com@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="auto"><div>I used a DictionaryLiteral only yesterday, and it turned what would have a typically unreadable array of Structs into something much more elegant. I&#39;m pretty sure the only reason Literals (of all varieties) aren&#39;t used more often is because Swift programmers don&#39;t realize they are available and easy to implement. <br></div></div></blockquote><div><br></div><div>Could you provide an example of how you used DictionaryLiteral?</div><span class="gmail-HOEnZb"><font color="#888888"><div><br></div><div>Nevin </div></font></span></div></div></div>
</blockquote></div><br></div></div></div>