Objective-c KVC: Collection Accessor Patterns for To-Many Properties, how can I use this to enhance my code?

后端 未结 3 1702
别那么骄傲
别那么骄傲 2021-01-02 21:20

I was reading :Collection Accessor Patterns for To-Many Properties, but I\'m not sure where can I or should I use this. Can someone please point out some scenarios that I ca

3条回答
  •  遥遥无期
    2021-01-02 21:46

    To add to this. Adopting these in your class API allows your class to take advantage of the same established generic coding behaviors in Foundation collections.

    One useful example would be the unordered collection. You could implement this so that all the public properties of your class are accessible as it were a dictionary. allKeys would return the property names. allValues would return the values of those properties. instanceOfYourClass[aPropertyName] would return the property aPropertyName

    This would allow quick iteration and introspection. Implementation would take some effort but would make a class fit nicely into KVC and KVO and add the ability to do simple and clever things with bindings as well.

提交回复
热议问题