So how do you define common class constants in Swift?
Problem
For a βnormalβ class, you can define them as follows:
class C { static let k = 1 } let a = Ck
But if you do the same in a generic class:
class C<T> { static let k = 1 }
You get the following compilation error:
Static stored properties are not yet supported in generic types
So how to solve this?
My current solution
I am now using struct to solve this problem:
struct CConstant { static let K = 1 }
It is not defined in the realm of the general class, but it works for me. Do you have a better solution?
-
ps: this is my first question here, so please help me improve this question if you consider it necessary =)
source share