KVO vs NSNotification vs protocol/delegates?

前端 未结 5 917
暖寄归人
暖寄归人 2020-12-12 14:24

I have some idea of which to use when but the exact usage is still not clear to me. Can someone explain with example?

5条回答
  •  青春惊慌失措
    2020-12-12 15:01

    Delegation is a design pattern that you use when you want some other object to modify the sender's behavior. Example: terminal windows avoid showing any lines or characters that are clipped by the window's edges, because the terminal window's delegate alters the size of the window to ensure this.

    Notification is a pattern to use when you don't need a response. Example: you get a notification that the system is about to go to sleep. The sender of that notification doesn't care what you do about it.

提交回复
热议问题