<div dir="ltr">Actually it&#39;s both - an object and a type. It&#39;s an object which describes itself.<div><br></div><div>Btw. I have the same problem with enum cases. They&#39;re values so why are they uppercase?</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 11, 2015 at 11:25 PM, Thorsten Seitz <span dir="ltr">&lt;<a href="mailto:tseitz42@icloud.com" target="_blank">tseitz42@icloud.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div></div><div>I like it. Just a minor suggestion: as an object is a value and not a type it should have a name starting with lower case, i.e.</div><div><br></div><div>object globalResource { ... }</div><div><br></div><div>-Thorsten </div><div><div class="h5"><div><br>Am 11.12.2015 um 23:07 schrieb Marc Knaup via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;:<br><br></div></div></div><blockquote type="cite"><div><div><div class="h5"><div dir="ltr">Hey guys,<div><br></div><div>I am working on a proposal which touches (and could even partially depend on) another interesting concept which I think would be a great addition for Swift.</div><div><br></div><div>Object declarations could be a way to declare a class or struct with exactly one instance. They are perfect for singletons, anonymous subclasses and to anonymously implement a protocol.</div><div><br></div><div>Here some examples how it could look like:</div><div><br></div><div><font face="monospace, monospace">// singleton</font></div><div><font face="monospace, monospace">object GlobalResource {</font></div><div><font face="monospace, monospace">    func doSomething() { … }</font></div><div><font face="monospace, monospace">}</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">let resource = GlobalResource</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">// could all be the same</font></div><div><font face="monospace, monospace">resource.doSomething()</font></div><div><font face="monospace, monospace">GlobalResource.doSomething()</font></div><div><font face="monospace, monospace">GlobalResource.Type.doSomething()</font></div><div><br></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">// anonymous subclass</font></div><div><font face="monospace, monospace">class ViewController: UIViewController {</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    override func loadView() {</font></div><div><font face="monospace, monospace">        view = object: UIView {</font></div><div><font face="monospace, monospace">            // configure view</font></div><div><font face="monospace, monospace">        }</font></div><div><font face="monospace, monospace">    }</font></div><div><font face="monospace, monospace">}</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">// anonymous protocol implementation</font></div><div><font face="monospace, monospace">protocol TapHandler {</font></div><div><font face="monospace, monospace">    func handleTap()</font></div><div><font face="monospace, monospace">}</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">view.tapHandler = object: TapHandler {</font></div><div><font face="monospace, monospace">    func handleTap() {</font></div><div><font face="monospace, monospace">        // …</font></div><div><font face="monospace, monospace">    }</font></div><div><font face="monospace, monospace">}</font></div><div><font face="monospace, monospace"><br></font></div><div><br></div><div>Kotlin is an example for a a modern language which uses this concept:</div><div><a href="https://kotlinlang.org/docs/reference/object-declarations.html" target="_blank">https://kotlinlang.org/docs/reference/object-declarations.html</a><br></div><div><br></div><div><br></div><div>What do you think about such an addition?</div></div>
</div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1MXK54sosN3xru3iYcLt0oBZ2w20i49gyogXctgrspclYknWzz65r2qhsqfUzXb55e8dPbQJaRSSYVaFlHffez6g4VLtOrCkXCtmlLicv9OVE5R7sllNX1f7eZV1Uui5u0PCH0nK0pctWVFSkXpljT374GGF4gmc7sEVh9vBh74j4GkuPCyOD1cfUqYi9V-2Fw4inGvpUEd26VdLd6M1oQDZMdqkUjav-2FoIoGUqDI8OaY-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div></blockquote></div><br></div>