Best practices for context parameter in addObserver (KVO)

后端 未结 3 965
不知归路
不知归路 2020-12-23 00:00

I was wondering what you should set the Context pointer in KVO when you are observing a property. I\'m just starting to use KVO and I haven\'t gleaned too much from the doc

3条回答
  •  太阳男子
    2020-12-23 00:38

    I think the better way would be to implement it as apple's doc says:

    The address of a uniquely named static variable within your class makes a good context.

    static void *PersonAccountBalanceContext = &PersonAccountBalanceContext;
    static void *PersonAccountInterestRateContext = &PersonAccountInterestRateContext;
    

    see documentation.

提交回复
热议问题