Closed p-x9 closed 11 months ago
@AssociatedObject(.OBJC_ASSOCIATION_ASSIGN) var test: String = "" { willSet { print("willSet: new", newValue) print(backgroundColor) } didSet { print("didSet: old", oldValue) } }
Old
get { objc_getAssociatedObject( self, &Self.__associated_testKey ) as? String ?? "" } set { let willSet: (String) -> Void = { [self] newValue in print("willSet: new", newValue) print(backgroundColor) } willSet(newValue) let oldValue = test objc_setAssociatedObject( self, &Self.__associated_testKey, newValue, .OBJC_ASSOCIATION_ASSIGN ) let didSet: (String) -> Void = { [self] oldValue in print("didSet: old", oldValue) } didSet(oldValue) }
New
get { objc_getAssociatedObject( self, &Self.__associated_testKey ) as? String ?? "" } set { let willSet: (String ) -> Void = { [self] newValue in print("willSet: new", newValue) print(backgroundColor) } willSet(newValue) let oldValue = test objc_setAssociatedObject( self, &Self.__associated_testKey, newValue, .OBJC_ASSOCIATION_ASSIGN ) let didSet: (String ) -> Void = { [self] oldValue in print("didSet: old", oldValue) } didSet(oldValue) }
Old
New