문제는 사용자가 static
변수를 사용하고 있기 때문에 발생합니다. static
변수를 덮어 쓸 수 없으며 전체 정지 할 수 없습니다. 여기서 논쟁 할 점이 없다. 당신이 class A {}
처럼, 대신 static
키워드의 class
키워드를 사용하고, 클래스 형을 무시할 수하는 class
(안 struct
)가있는 경우
첫 번째 문장 말한다. 즉, 같은 목적으로 두 개의 키워드를 사용할 수 있으며, 큰 차이점은 static
을 덮어 쓸 수 없다는 것을 의미합니다.
class B: A {
// Class type computed property can be overwritten
override class var overridableClassPropery: String {
return "This is class B's overwritten property"
}
}
편집 :
class A {
// overridable computed property
class var overridableClassPropery: String {
return "This is class A's overwritten property"
}
// Not overridable `static` computed property
// Error will be shown if you try to override this property in class `B`
static var notOverridableStaticPropery: String {
return "Can not override this property in a subclass"
}
}
두 번째는 당신이 수퍼 클래스의 속성을 재정의하고, 다음과 같이, 서브 클래스에서 자신의 get
구현을 제공 할 수 있음을 말한다 notOverridableStaticPropery
이 class A
이면 class B
에 의해 상속되며, 이는 사용자가 class B
을 통해 액세스하거나 호출 할 수 있음을 의미합니다. 하지만은 무시할 수 없으며 항상 class A
에 설정된 값을 갖습니다.
print(A.notOverridableStaticPropery) // prints "This is class A's not overridable static property"
print(B.notOverridableStaticPropery) // prints "This is class A's not overridable static property"
달성하고자하는 것은 무엇입니까? 'static' 속성을 오버라이드 할 수는 없지만 다른 변수로 할 수 있습니다. – NSDmitry
Swift3에서 언급 한 두 문장의 의미를 이해할 수 없습니다. 상속 된 유형 특성을 대체하여 해당 특성에 대한 사용자 정의 게터 및 설정자를 제공 할 수 있다고 말합니다. – cary