I would like to know the advantages and disadvantages of various methods of value transmission in IOS. I especially want to know the advantages and disadvantages of attribute value transmission and proxy value transmission, notification and block value transmission?

  ios, question

I would like to know the advantages and disadvantages of various methods of value transmission in IOS. I especially want to know the advantages and disadvantages of attribute value transmission and proxy value transmission, notification and block value transmission?

At present, I only know agents and attributes, but I don’t know what’s the difference between the two. I asked for advice for Xiao Bai ~ ~ I searched a lot and didn’t have detailed information if you have trouble under the guidance.

1. Attributes are the most direct. Two objects can be directly contacted. For example, a UIViewControllerA inside constructs a UIImageView to provide a picture for UIImageView.
2. The agent’s environment is generally: A operates B, then B does not return the result immediately, and when the waiting condition is satisfied, B returns to inform A. Common is the network request, which is characterized by a return action.
3. block is similar to delegate in behavior and is also used for callback. But (1)block is a bit more enjoyable to write, such as playing a box, clicking on the event callback after the box pops up, I build an alertView, and immediately I can write its callback alertView.clickBlock = xxx, while delegate I will also build another method (2)block will copy its internal objects, which will have a good isolation effect, such as A is a common single instance. B->A->C, then c processes callbacks b, E->A->F, then f processes callbacks e, if it is delegate, after c callbacks to a, is a callback to b or e? A i don’t know. However, block will copy the object, and B will copy itself in when creating block. The callback object obtained by C is B. This is a bit difficult to understand.
4. Notices are relative to the first two: (1) One-to-many, one notification is sent out, and all recipients respond and are synchronized. (2) There is no direct connection between the sender and the receiver, especially in the complex project of inside, when two objects cannot contact each other, the message can be sent by notification, which is easy to mess up. For example, if the login is successful, there may be many places to update the data. However, the login module focuses on login and should not manage what to do after the login is successful. Therefore, notification is better. Of course, try to minimize cross-fertilization of projects.