Http Stubs: let’s go Swift Swizzling!
Last weeks, I was delving into http and Swift with my friend Christos. To write robust code, we need unit tests of course and to isolate testing layer: you need a HTTP stub.
When we worked with Objective-C, we used to mock http calls with OHTTPStubs. So we thought we could carry on using it with our brand new Swift code. After all, Swift and Objective-C are interoperable. However, there are subtle differences with iOS8 and when trying to use OHTTPSubs obj-c lib with Swift code, we ran into this issue (merged now!).
Get corinne’s stories in your inbox
Join Medium for free to get updates from this writer.
But when you delve into some neat code, then the urge of writing your own is showing up… It wasn’t long before my friend Christos came up with AGURLSessionStubs a http stub written entirely in Swift.
With this blog post, I’d like to share with you the inside of stubbing http library. Let’s dig under the hood to see how http mock are implemented in Objective-C and how we can apply the same concepts (with some restrictions) in Swift.
Happy Swifting and Swizzling!








