logo dotConferences

Tiny Networking in Swift

Chris Eidhof at dotSwift 2016

Chris looks at how we can take standard networking code, and use Swift's features to make it generic and simple. While live-coding, he factors out common parts into a struct, so that the resulting code is easy to test and highly reusable.

More details

Chris' comments:

I try to make the the case for creating a simple wrapper around networking code. Rather than having a lot of asynchronous code (which is hard to test), I try to minimize the asynchronous part and instead use generics and structs to make it simpler and more testable.

I took this code from an existing app we wrote in production, and wrote a blog post about it in 2014: http://chris.eidhof.nl/posts/tiny-networking-in-swift.html. In my recent book Advanced Swift, we go into more detail explaining these techniques. Over the last years, a number of companies have used a variant of this library in production, and are quite happy with it.

After watching the talk, you'll see that there are a number of things that can be improved: how to parse other things than JSON? How can you make it asynchronous? How can you handle POST requests? I hope that you take these challenges, and see if you can add these features. It'll be lots of fun!