What is the purpose of an iOS delegate?

前端 未结 11 1527
野性不改
野性不改 2020-12-18 23:22

I understand what a delegate does in iOS, and I\'ve looked at sample code, but I\'m just wondering about the advantages of this type of encapsulation (as opposed to includin

11条回答
  •  无人及你
    2020-12-18 23:26

    In iOS, delegation requires the "delegate" class to implement a protocol which contain methods that the "delegating" knows about. Still following?

    The delegating class's implementation will call these protocol methods, but the delegate class will implement these methods in their class.

    This keeps your Classes clean.

    In reality, you don't really need delegation if you can add new methods to a single class. But for UIKIT's UIView class, Apple will not allow you to add new implementations to their class.

    correct me if I'm wrong.

提交回复
热议问题