Daily iOS
Networking

Synchronous requests and moving to async/await

The legacy code has a function that waits on a URLSession response with DispatchSemaphore to make it "synchronous," and older spots still use NSURLConnection.sendSynchronousRequest. Why is that a problem?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

A synchronous wait ties up the calling thread: on main it freezes the UI and gets the app killed by the watchdog, and on a pool thread it drains the pool. NSURLConnection was replaced by URLSession in iOS 9.

Share a question