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)

› Should you write reusable code or write code that fits the use case?

Great answer on Quora from one of the developers of Spotify.

I often find myself in situations exactly like the one Mattias creates here. Multiple calls to the same service, with just slight variations between one another.

I’ve learned the hard way to manage this kind of behavior while writing code.

What I think should resonate here:

Wait for three instances of duplication before generalizing.