[swift-evolution] [discussion] Class stored properties?

Charlie Monroe charlie at charliemonroe.net
Wed Aug 9 06:01:17 CDT 2017


Hi,

can you provide a usecase for this? I remember this being used in ObjC for +version, but I'm not sure anymore where I'd use this...

BTW you don't need to stringify, use ObjectIdentifier (part of stdlib).

> On Aug 9, 2017, at 12:54 PM, Mathew Huusko V via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Curious if class stored properties have ever been discussed (doesn't seem so..)?
> 
> 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..
> 
> class SomeClass {
>     private static var _classValues = [SomeClass.Type: Int]()
> 
>     class var value: Int {
>         get { _classValues[self] }
>         set { _classValues[self] = newValue }
>     }
> }
> 
> .. but then I remembered types aren't hashable yet either (so I guess I need to stringify it first).
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list