What is the point of key-value coding?

前端 未结 3 1708
野性不改
野性不改 2021-02-01 07:15

Since Objective-C 2.0, we\'ve had @properties and autogenerated accessor methods. So today, what is the point of key-value coding? Under what circumstances is it

3条回答
  •  攒了一身酷
    2021-02-01 07:33

    KVC can be useful if you are using Key Value Observers to detect value changes on an object. If you wanted to use KVO and @properties you would have to wrap every mutator method with:

    [self willChangeValueForKey:@"bar"];
    bar = foo;
    [self didChangeValueForKey:@"bar"];
    

提交回复
热议问题