sjrmanning / Birdsong

:bird::musical_score: Swift WebSockets client for Phoenix Channels.
MIT License
127 stars 37 forks source link

WebSocketDelegate extension for Socket #6

Closed SoroushE closed 7 years ago

SoroushE commented 8 years ago

Hi Simon,

Your library was such a relief when SwiftPhoenixClient couldn't support presence :) But, I was wondering why you did not provide delegation for your socket class or your channels instead of setting callbacks in onConnect method.

Thanks for your help, Soroush

sjrmanning commented 7 years ago

Hi Souroush,

Thanks! Glad the library is helpful for you. As for your question, I simply prefer using block callbacks as I think for this particular library it's the more simple and elegant solution.

For example, if we used delegates, then if you're managing multiple joined channels in your controller, your delegate implementation has to check which channel its getting called for each time it receives a message. Blocks let us easily specify what to do for each channel individually as needed.

We also have to worry less about circular references, as delegates are owned and could be captured. Closures also just seem a bit more "Swift"y — the syntax works better I think.

Hope that answers your question! and apologies for the late reply.

Cheers, Simon