NSNotificationCenter vs delegation( using protocols )?

前端 未结 6 625
天涯浪人
天涯浪人 2020-11-27 10:56

What are the pros and cons of each of them?
Where should I use them specifically?

6条回答
  •  渐次进展
    2020-11-27 11:43

    Notifications are better for decoupling UI components. It allows you to plug any view without any modification in your controllers or models. Definitely better for loosely-coupled design.

    But for the performance between delegation and notification, you need to think about the frequency of the call.

    Delegation might be better for more frequent events, notifications are better for less frequent events but more recipients. It's up to project what to pick.

提交回复
热议问题