iOS Swift: Closures (Callbacks) versus Delegates, when to use which? [closed]

依然范特西╮ 提交于 2019-12-02 18:14:28

(Opinion based answer for an opinion based question)

The questions shouldn't be which is better, it should be what's the best solution for the problem I'm trying to solve.

My simple rule: if something requires one function as it's interface, a callback is usually a good solution. If more than one function is required, especially when they're required for the basic function of an object, a Delegate is probably a better solution.

As always it depends on the specific situation, but absolute statements rarely work out in real-world usage.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!