0
클래스 내부에서 설정되는 속성을 제한하는 어떤 방법이 있습니까? 문제를 설명하는 코드는 다음과 같습니다.클래스 내부에서 함수 내부에서 거부 속성 편집
import UIKit
class MyViewController: UIViewController {
var property: Int?
func setProperty(_ property: Int?, animated: Bool,
withColor color: UIColor,
andSomethingElse something: Any) {
// only allow property to be set here
self.property = property
// ...
}
override func viewDidLoad() {
super.viewDidLoad()
// What I'd like to achieve is deny following...
property = 42
// ...and somehow force to set value exclusively via function
setProperty(42,
animated: true,
withColor: .green,
andSomethingElse: LongCat())
}
}