在类和结构的代码中,willSet和didSet观察者是一个东西吗?它们是真正面向对象的编程。很多Sulo代码所以只想知道
如果我正确理解你的问题,是的,Swift有内置的setSet和didSet属性观察:
struct SomeStruct {
var someProperty: Int {
willSet {
print("Hello, ")
}
didSet {
print("World!")
}
}
}
class SomeClass {
var someProperty: Int {
willSet {
print("Hello, ")
}
didSet {
print("World!")
}
}
}