<html><head><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=""><div class="">Class variables are not common, but they are the most natural way to implement class-specific functionality. Off the top of my head, I have used class variables for:</div><div class=""><br class=""></div><div class="">1) Custom allocation schemes, e.g. pools, LRU implementations</div><div class="">2) Diagnostics, e.g. counting the number of instances of a given class</div><div class="">3) Plugin-in functionality, e.g. customizing behavior of a class at runtime. In Swift, the variables would be closures.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">You can argue that class variables these are not strictly necessary for these tasks, but I have found them to be handy, including during development and “Bring-up"</div><div class=""><br class=""></div><div class="">- Chris</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 9, 2017, at 12:52 PM, Mathew Huusko V via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I don't follow. What's a singleton/how? If you mean my example, the whole point/need for the feature is so it's not. I want `.value` to be unique storage for each subclass.</div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Aug 9, 2017 at 7:09 PM, Robert Widmann <span dir="ltr" class=""><<a href="mailto:rwidmann@apple.com" target="_blank" class="">rwidmann@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This is a singleton, it just happens to be in class scope.<br class="">
<span class="HOEnZb"><font color="#888888" class=""><br class="">
~Robert Widmann<br class="">
</font></span><div class="HOEnZb"><div class="h5"><br class="">
> On Aug 9, 2017, at 3:55 AM, Mathew Huusko V via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class="">
><br class="">
> Curious if class stored properties have ever been discussed (doesn't seem so..)?<br class="">
><br class="">
> Also, assuming no, and assuming there's a good reason no/they're not coming anytime soon, what are some patterns people have been using in their place? I was considering something like..<br class="">
><br class="">
> class SomeClass {<br class="">
> private static var _classValues = [SomeClass.Type: Int]()<br class="">
><br class="">
> class var value: Int {<br class="">
> get { _classValues[self] }<br class="">
> set { _classValues[self] = newValue }<br class="">
> }<br class="">
> }<br class="">
><br class="">
> .. but then I remembered types aren't hashable yet either (so I guess I need to stringify it first).<br class="">
</div></div><div class="HOEnZb"><div class="h5">> ______________________________<wbr class="">_________________<br class="">
> swift-evolution mailing list<br class="">
> <a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-<wbr class="">evolution</a><br class="">
<br class="">
</div></div></blockquote></div><br class=""></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>