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

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


(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.


matomo