Why is the stored property class not supported in classes?

Basically, Swift doesn't let me do this -

// stored class properties that are not supported in classes, you meant "static".

class var hello = "hello"

However, it’s beautiful -

static var hi = "hi"

I know that the difference between Class and Static in Swift is that class variables cannot store stored properties, but static variables can. However, the fundamental difference between class and static variables is that static variables cannot be overridden in subclasses, while class variables can. This is the functionality that I want to keep.

I know that a simple fix for this problem is to make it a computed property using a hack fix like this -

class var Greeting : String {
    return "Greeting"
}

, , . , , -, Swift .

+6
1

, swift , ,

" , "

enter image description here

0

All Articles