KVC: In simple terms, it is the Access class property that accesses the object property through a string.
1. Set key-value pairs only for class properties
2, set Setvalue:forkey:, that is, Forkey can only be class properties
3, Value Valueforkey
KVO: proactively notifies observers when the attributes of the observer are modified by KVC.
1, using KVC to set the class properties
2, Registered observing object AddObserver:forKeyPath:options:context:
3. The Observer class must override the method ObserveValueForKeyPath:ofObject:change:context:
4, application, MVC model, the database (Datamodal) changes, resulting in a view change, in this way to achieve very convenient
KVC and KVO are used together.
Protocol: A personal understanding is a list of methods that defines several methods that can be implemented by any class.
Principal Agent: Implements the Protocol method.
Feel the agent is difficult to accurately use a noun to say, it is more like a relationship, I want to give my husband a bouquet of flowers, but outside the wind is very cold, I commissioned a flower shop for me to send flowers to my husband, then the florist will abide by the agreement for me to send me. The florist has become my agent.
Using Setdelegate to set proxy objects, the most typical example is the common TableView. There is a control chain relationship, the notification is not. Control chain:
A single owned and controllable correspondence relationship.
Pros: The classes that support it have detailed and specific information.
Disadvantage: The class must support delegates. There can be only one delegate connected to an object at a time.
Notification: There are many applications, in the Settings option has the option to set the page style. For example, change the background color, or set the font. At this time, the notification is a good choice.
Notification needs to have a notification center:nsnotificationcenter, custom notifications need to give a name, and then listen.
Pros: Both the sender and the recipient of the notification do not need to know each other. You can specify the specific method to receive notifications. The notification name can be any string.
Cons: More key-value observations (KVO) require multipoint code, and listeners must be removed before deleting them.
iOS Development KVC KVO Principal Agent Protocol notification summary and usage scenarios