when to use “willChangeValueForKey” and “didChangeValueForKey”?

前端 未结 8 809
我在风中等你
我在风中等你 2021-01-30 10:53

I saw these lines in a demo project, but I couldn\'t understand why it did that.

[self willChangeValueForKey:@\"names\"];
[self didChangeValueForKey:@\"names\"];         


        
8条回答
  •  离开以前
    2021-01-30 11:44

    • If you want to do stuff just before the value gets changed, use willChangeValueForKey.
    • If you want to do stuff just after the value gets changed, use didChangeValueForKey.

    Edit: ignore me, was reading too fast - Barry is right :-)

提交回复
热议问题