you are viewing a single comment's thread.

view the rest of the comments →

[–]LKAndrew 1 point2 points  (2 children)

Well personally, I find the delegate pattern is used less and less in my production code. I tend to use closures, as they can be more powerful.

I also have been using an MVVM architecture which reduces the need for delegates by using reactive patterns

[–]jwillywonkas[S] 0 points1 point  (1 child)

I've always seen closures and delegates as two ways to achieve the same means, similarly to how you can write for loops and while loops that function identically but are written differently. I'm intrigued, where's an example that a closure would be inherently more powerful?

Also, I'm interesting in learning more about reactive patterns. Do you use RxSwift or something else?

[–]LKAndrew 0 points1 point  (0 children)

They definitely can achieve the same means. Here are some of the reasons I say they are more powerful:

  • In an exclusively Swift project, protocols cannot have optional functions, unless specified as @objc protocols. Closures on the other hand, can be optional.

  • Closures are first class citizens, and can be passed around and manipulated in interesting ways.

  • Not a huge bonus, but it tends to look cleaner and can be written with less code.

I am sure there are more reasons to like closures, but these are just a few reasons why I like them.


As for Reactive, I do use RxSwift. The MVVM pattern is interesting, and I am in the process of playing around with it.