Working with backend services on iOS

(Naji Esiri) #1

(Steven B Schofield) #2

Nice article.

I’m curious about your use of Structs & Protocols over Classes. Still getting to grips with such Swift concepts…

What was your thought process?

(Andy Smart) #3

Hey Steven, thanks!

We’re a big fan of value types in Swift, since they provide proper immutability out of the box. Given that classes are reference counted, they often have unwanted side effects when copying or passing between other reference counted objects.

In general, we default to a value type unless we need reference counting.

For protocols, this gives us a way to define common interfaces for objects without resorting to inheritance, so again - we’re big fans of this. It allows us to standardise designs for our models in particular, and means that interfaces further up the stack don’t need to know about concrete types, only caring about protocol conformance - this is really great for extensibility.

(Arvind Ravi) #4

That was an excellent article, Andy. Gives a lot of insight about how services are architected, the thought process behind it. I’ve been there myself and have often thought about how other people do it. I enjoyed reading it. Thanks!