public class Demo : NSObject{
@objc fileprivate var name = "123"
func namePrint(){
print(name)
}
}
var demo = Demo()
demo.namePrint()//123
objc_setAssociatedObject(demo, "name", "321", objc_AssociationPolicy(rawValue: 3)!)
demo.namePrint()//123
demo.setValue("321", forKey: "name")
demo.namePrint()//321
网友评论