我想创建一个属性包装器,它使我的UICollectionViewLayout
.
因此我创建了这个属性包装器
@propertyWrapper
class LayoutInvalidating {
private let layout: UICollectionViewLayout
init(layout: UICollectionViewLayout) {
self.layout = layout
self.wrappedValue = layout
}
var wrappedValue: UICollectionViewLayout {
didSet {
self.layout.invalidateLayout()
}
}
}
然后我想如下使用它
final class VehicleControlsCollectionViewLayout: UICollectionViewLayout {
@LayoutInvalidating(layout: self) // self is not alive
public var itemSize: CGSize = .init(width: 70, height: 70)
}
每次设置属性时,我都想调用self.invalidateLayout()
. 有什么想法可以在 self 存在时访问它吗?