How to run networking code on Swift Playgrounds

I’m sure most of you know this by now.

If you’re mocking your network calls using Swift on a Playground, it is important to tell the Playground that it can run code asynchronously.

Import XCPlayground and call XCPSetExecutionShouldContinueIndefinitely with a true argument.

import XCPlayground

XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: true)